From: Enju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com> Date: Wed, 6 Apr 2022 15:40:49 +0000 (+0200) Subject: added user-agent X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=eee3cd6c9b39d46673051278e394fe153cfb28df;p=fba.git added user-agent --- diff --git a/fetch_blocks.py b/fetch_blocks.py index eb4f718..d79eddc 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -3,6 +3,9 @@ from hashlib import sha256 import sqlite3 from bs4 import BeautifulSoup +headers = { + "user-agent": "fedi-block-api (https://gitlab.com/EnjuAihara/fedi-block-api)" +} def get_mastodon_blocks(domain: str) -> dict: try: @@ -10,7 +13,7 @@ def get_mastodon_blocks(domain: str) -> dict: media_removal = [] federated_timeline_removal = [] - doc = BeautifulSoup(get(f"https://{domain}/about/more").text, "html.parser") + doc = BeautifulSoup(get(f"https://{domain}/about/more", headers=headers, timeout=5).text, "html.parser") for header in doc.find_all("h3"): if header.text == "Suspended servers": for line in header.find_next_siblings("table")[0].find_all("tr")[1:]: @@ -27,7 +30,7 @@ def get_mastodon_blocks(domain: str) -> dict: def get_type(domain: str) -> str: try: - res = get("https://"+domain, timeout=5) + res = get("https://"+domain, headers=headers, timeout=5) if "pleroma" in res.text.lower(): print("pleroma") return "pleroma" @@ -42,7 +45,8 @@ def get_type(domain: str) -> str: conn = sqlite3.connect("blocks.db") c = conn.cursor() -c.execute("select domain, software from instances where software in ('pleroma', 'mastodon')") +#c.execute("select domain, software from instances where software in ('pleroma', 'mastodon')") +c.execute("select 'chizu.love', 'pleroma'") for blocker, software in c.fetchall(): if software == "pleroma": @@ -50,7 +54,7 @@ for blocker, software in c.fetchall(): try: # Blocks c.execute("delete from blocks where blocker = ?", (blocker,)) - json = get(f"https://{blocker}/nodeinfo/2.1.json").json() + json = get(f"https://{blocker}/nodeinfo/2.1.json", headers=headers, timeout=5).json() if "mrf_simple" in json["metadata"]["federation"]: for mrf in json["metadata"]["federation"]["mrf_simple"]: for blocked in json["metadata"]["federation"]["mrf_simple"][mrf]: