From: Roland Häder Date: Wed, 24 May 2023 12:43:32 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c4e5e060d343b9426acfc64fe3ab9e1bb226687d;p=fba.git Continued: - tidyup() used for header.text - moved translations table to header - renamed variable --- diff --git a/fba.py b/fba.py index 3042952..c035291 100644 --- a/fba.py +++ b/fba.py @@ -56,6 +56,31 @@ nodeinfos = { "get_peers_url": {}, } +language_mapping = { + # English -> English + "Silenced instances" : "Silenced servers", + "Suspended instances" : "Suspended servers", + "Limited instances" : "Limited servers", + # Mappuing German -> English + "Gesperrte Server" : "Suspended servers", + "Gefilterte Medien" : "Filtered media", + "Stummgeschaltete Server" : "Silenced servers", + # Japanese -> English + "停止済みのサーバー" : "Suspended servers", + "制限中のサーバー" : "Limited servers", + "メディアを拒否しているサーバー": "Filtered media", + "サイレンス済みのサーバー" : "Silenced servers", + # ??? -> English + "שרתים מושעים" : "Suspended servers", + "מדיה מסוננת" : "Filtered media", + "שרתים מוגבלים" : "Silenced servers", + # French -> English + "Serveurs suspendus" : "Suspended servers", + "Médias filtrés" : "Filtered media", + "Serveurs limités" : "Limited servers", + "Serveurs modérés" : "Limited servers", +} + # URL for fetching peers get_peers_url = "/api/v1/instance/peers" @@ -603,25 +628,6 @@ def get_mastodon_blocks(domain: str) -> dict: "Silenced servers" : [], } - translations = { - "Silenced instances" : "Silenced servers", - "Suspended instances" : "Suspended servers", - "Gesperrte Server" : "Suspended servers", - "Gefilterte Medien" : "Filtered media", - "Stummgeschaltete Server" : "Silenced servers", - "停止済みのサーバー" : "Suspended servers", - "制限中のサーバー" : "Limited servers", - "メディアを拒否しているサーバー": "Filtered media", - "サイレンス済みのサーバー" : "Silenced servers", - "שרתים מושעים" : "Suspended servers", - "מדיה מסוננת" : "Filtered media", - "שרתים מוגבלים" : "Silenced servers", - "Serveurs suspendus" : "Suspended servers", - "Médias filtrés" : "Filtered media", - "Serveurs limités" : "Limited servers", - "Serveurs modérés" : "Limited servers", - } - try: doc = bs4.BeautifulSoup( reqto.get(f"https://{domain}/about/more", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"])).text, @@ -633,10 +639,11 @@ def get_mastodon_blocks(domain: str) -> dict: return {} for header in doc.find_all("h3"): - header_text = header.text + header_text = tidyup(header.text) - if header_text in translations: - header_text = translations[header_text] + if header_text in language_mapping: + print(f"DEBUG: header_text='{header_text}'") + header_text = language_mapping[header_text] if header_text in blocks or header_text.lower() in blocks: # replaced find_next_siblings with find_all_next to account for instances that e.g. hide lists in dropdown menu