# NOISY-DEBUG: print("DEBUG: Cannot fetch API request:", request)
pass
- if json is None:
+ # NOISY-DEBUG: print("DEBUG: json[]:", type(json))
+ if json is None or len(json) == 0:
print("WARNING: Failed fetching nodeinfo from domain:", domain)
# NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json))
software = None
json = fetch_nodeinfo(domain)
- if len(json) == 0:
- print("DEBUG: Could not determine software type:", domain)
+ # NOISY-DEBUG: print("DEBUG: json[]:", type(json))
+
+ if json is None or len(json) == 0:
+ # NOISY-DEBUG: print("DEBUG: Could not determine software type:", domain)
+ return None
+
+ # NOISY-DEBUG: print("DEBUG: json():", len(json), json)
+ if "software" not in json or "name" not in json["software"]:
+ print("WARNING: JSON response does not include [software][name], guessing ...")
+ found = 0
+ for element in {"uri", "title", "description", "email", "version", "urls", "stats", "thumbnail", "languages", "contact_account"}:
+ if element in json:
+ found = found + 1
+
+ # NOISY-DEBUG: print("DEBUG: Found elements:", found)
+ if found == len(json):
+ # NOISY-DEBUG: print("DEBUG: Maybe is Mastodon:", domain)
+ return "mastodon"
+
+ print("WARNING: Cannot guess software type:", domain, found, len(json))
return None
- # NOISY-DEBUG: print("DEBUG: json():", len(json))
software = tidyup(json["software"]["name"])
# NOISY-DEBUG: print("DEBUG: tidyup software:", software)
return software
def update_block_reason(reason: str, blocker: str, blocked: str, block_level: str):
- # NOISY: print("--- Updating block reason:", reason, blocker, blocked, block_level)
+ # NOISY: # NOISY-DEBUG: print("DEBUG: Updating block reason:", reason, blocker, blocked, block_level)
try:
cursor.execute(
"UPDATE blocks SET reason = ?, last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason = ''",
sys.exit(255)
def update_last_seen(blocker: str, blocked: str, block_level: str):
- # NOISY: print("--- Updating last_seen for:", blocker, blocked, block_level)
+ # NOISY: # NOISY-DEBUG: print("DEBUG: Updating last_seen for:", blocker, blocked, block_level)
try:
cursor.execute(
"UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ?",
print("WARNING: Bad blocked:", blocked)
raise
- print("--- New block:", blocker, blocked, reason, block_level, first_added, last_seen)
+ print("INFO: New block:", blocker, blocked, reason, block_level, first_added, last_seen)
try:
cursor.execute(
"INSERT INTO blocks (blocker, blocked, reason, block_level, first_added, last_seen) VALUES(?, ?, ?, ?, ?, ?)",
software = determine_software(domain)
# NOISY-DEBUG: print("DEBUG: Determined software:", software)
- print(f"--- Adding new instance {domain} (origin: {origin})")
+ print(f"INFO: Adding new instance {domain} (origin: {origin})")
try:
cursor.execute(
"INSERT INTO instances (domain, origin, originator, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",