import re
import reqto
import json
+import os
import sqlite3
import sys
+import tempfile
import time
import validators
+import zc.lockfile
with open("config.json") as f:
config = json.loads(f.read())
re.compile("^[a-f0-9]{7}$"),
]
+# Lock file
+lockfile = tempfile.gettempdir() + '/.' + __name__ + '.lock'
+LOCK = None
+
##### Cache #####
def is_cache_initialized(key: str) -> bool:
string = re.sub("(.+)\@", "", string)
return string
+
+def lock_process():
+ global LOCK
+ try:
+ print(f"DEBUG: Acquiring lock: '{lockfile}'")
+ LOCK = zc.lockfile.LockFile(lockfile)
+ print("DEBUG: Lock obtained.")
+
+ except zc.lockfile.LockError:
+ print(f"ERROR: Cannot aquire lock: '{lockfile}'")
+ sys.exit(100)
+
+def shutdown():
+ print("DEBUG: Closing database connection ...")
+ connection.close()
+ print("DEBUG: Releasing lock ...")
+ LOCK.close()
+ print(f"DEBUG: Deleting lockfile='{lockfile}' ...")
+ os.remove(lockfile)
+ print("DEBUG: Shutdown completed.")
import validators
import fba
+fba.lock_process()
+
domains = list()
try:
fetched = fba.post_json_api("gql.api.bka.li", "/v1/graphql", json.dumps({
print(f"INFO: Fetching instances from domain='{domain}' ...")
fba.fetch_instances(domain, None, None, sys.argv[0])
-fba.connection.close()
+fba.shutdown()
import validators
import fba
+fba.lock_process()
+
fba.cursor.execute(
"SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe') AND (last_blocked IS NULL OR last_blocked < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_block"]]
)
blockdict = []
-fba.connection.close()
+fba.shutdown()
import sys
import fba
+fba.lock_process()
+
feed = sys.argv[1]
domains = list()
print(f"INFO: Fetching instances from domain='{domain}' ...")
fba.fetch_instances(domain, None, None, sys.argv[0])
-fba.connection.close()
+fba.shutdown()
import validators
import fba
+fba.lock_process()
+
instance = sys.argv[1]
# Initial fetch
print(f"INFO: Fetching instances for instance '{row[0]}' ('{row[2]}') of origin='{row[1]}',nodeinfo_url='{row[3]}'")
fba.fetch_instances(row[0], row[1], row[2], sys.argv[0], row[3])
-fba.connection.close()
+fba.shutdown()