From c4e5e060d343b9426acfc64fe3ab9e1bb226687d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 24 May 2023 14:43:32 +0200 Subject: [PATCH] Continued: - tidyup() used for header.text - moved translations table to header - renamed variable --- fba.py | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) 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 -- 2.39.5