-headers = {
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0"
-}
-
-
-def get_mastodon_blocks(domain: str) -> dict:
- blocks = {
- "Suspended servers": [],
- "Filtered media": [],
- "Limited servers": [],
- "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",
- "メディアを拒否しているサーバー": "Filtered media",
- "サイレンス済みのサーバー": "Silenced servers",
- "Serveurs suspendus": "Suspended servers",
- "Médias filtrés": "Filtered media",
- "Serveurs limités": "Silenced servers",
- }
-
- try:
- doc = BeautifulSoup(
- get(f"https://{domain}/about/more", headers=headers, timeout=5).text,
- "html.parser",
- )
- except:
- return {}
-
- for header in doc.find_all("h3"):
- header_text = header.text
- if header_text in translations:
- header_text = translations[header_text]
- if header_text in blocks:
- # replaced find_next_siblings with find_all_next to account for instances that e.g. hide lists in dropdown menu
- for line in header.find_all_next("table")[0].find_all("tr")[1:]:
- blocks[header_text].append(
- {
- "domain": line.find("span").text,
- "hash": line.find("span")["title"][9:],
- "reason": line.find_all("td")[1].text.strip(),
- }
- )
- return {
- "reject": blocks["Suspended servers"],
- "media_removal": blocks["Filtered media"],
- "followers_only": blocks["Limited servers"]
- + blocks["Silenced servers"],
- }
-
-def get_friendica_blocks(domain: str) -> dict:
- blocks = []
-
- try:
- doc = BeautifulSoup(
- get(f"https://{domain}/friendica", headers=headers, timeout=5).text,
- "html.parser",
- )
- except:
- return {}
-
- blocklist = doc.find(id="about_blocklist")
- for line in blocklist.find("table").find_all("tr")[1:]:
- blocks.append(
- {
- "domain": line.find_all("td")[0].text.strip(),
- "reason": line.find_all("td")[1].text.strip()
- }
- )
-
- return {
- "reject": blocks
- }
-
-def get_pisskey_blocks(domain: str) -> dict:
- blocks = {
- "suspended": [],
- "blocked": []
- }
-
- try:
- counter = 0
- step = 99
- while True:
- # iterating through all "suspended" (follow-only in its terminology) instances page-by-page, since that troonware doesn't support sending them all at once
- try:
- if counter == 0:
- doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"suspended":True,"limit":step}), headers=headers, timeout=5).json()
- if doc == []: raise
- else:
- doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"suspended":True,"limit":step,"offset":counter-1}), headers=headers, timeout=5).json()
- if doc == []: raise
- for instance in doc:
- # just in case
- if instance["isSuspended"]:
- blocks["suspended"].append(
- {
- "domain": instance["host"],
- # no reason field, nothing
- "reason": ""
- }
- )
- counter = counter + step
- except:
- counter = 0
- break
+# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
+# Copyright (C) 2023 Free Software Foundation
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.