update_last_error(domain, json["message"])
return None
elif "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", "short_description", "description", "email", "version", "urls", "stats", "thumbnail", "languages", "contact_account", "registrations", "approval_required"}:
- # NOISY-DEBUG: print("DEBUG: element:", element)
- 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(f"WARNING: Cannot guess software type: domain='{domain}',found={found},json()={len(json)}")
- return None
+ # NOISY-DEBUG: print(f"DEBUG: JSON response from {domain} does not include [software][name], fetching / ...")
+ try:
+ res = reqto.get(f"https://{domain}/", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
+
+ # NOISY-DEBUG: print("DEBUG: domain,res.ok,res.status_code:", domain, res.ok, res.status_code)
+ if res.ok and res.status_code < 300 and len(res.text) > 0:
+ # NOISY-DEBUG: print("DEBUG: Search for <meta name='generator'>:", domain)
+
+ doc = bs4.BeautifulSoup(res.text, "html.parser")
+ # NOISY-DEBUG: print("DEBUG: doc[]:", type(doc))
+
+ tag = doc.find("meta", {"name": "generator"})
+ # NOISY-DEBUG: print(f"DEBUG: tag[{type(tag)}: {tag}")
+ if isinstance(tag, bs4.element.Tag):
+ # NOISY-DEBUG: print("DEBUG: Found generator meta tag:", domain)
+ software = tidyup(tag.get("content"))
+
+ except BaseException as e:
+ print(f"WARNING: Cannot fetch / from '{domain}':", e)
+ update_last_error(domain, e)
+ pass
+
+ # NOISY-DEBUG: print(f"DEBUG: Generator for domain='{domain}' is: {software}, EXIT!")
+ return software
software = tidyup(json["software"]["name"])