added user-agent
This commit is contained in:
parent
e4dd3a6346
commit
eee3cd6c9b
@ -3,6 +3,9 @@ from hashlib import sha256
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"user-agent": "fedi-block-api (https://gitlab.com/EnjuAihara/fedi-block-api)"
|
||||||
|
}
|
||||||
|
|
||||||
def get_mastodon_blocks(domain: str) -> dict:
|
def get_mastodon_blocks(domain: str) -> dict:
|
||||||
try:
|
try:
|
||||||
@ -10,7 +13,7 @@ def get_mastodon_blocks(domain: str) -> dict:
|
|||||||
media_removal = []
|
media_removal = []
|
||||||
federated_timeline_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"):
|
for header in doc.find_all("h3"):
|
||||||
if header.text == "Suspended servers":
|
if header.text == "Suspended servers":
|
||||||
for line in header.find_next_siblings("table")[0].find_all("tr")[1:]:
|
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:
|
def get_type(domain: str) -> str:
|
||||||
try:
|
try:
|
||||||
res = get("https://"+domain, timeout=5)
|
res = get("https://"+domain, headers=headers, timeout=5)
|
||||||
if "pleroma" in res.text.lower():
|
if "pleroma" in res.text.lower():
|
||||||
print("pleroma")
|
print("pleroma")
|
||||||
return "pleroma"
|
return "pleroma"
|
||||||
@ -42,7 +45,8 @@ def get_type(domain: str) -> str:
|
|||||||
conn = sqlite3.connect("blocks.db")
|
conn = sqlite3.connect("blocks.db")
|
||||||
c = conn.cursor()
|
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():
|
for blocker, software in c.fetchall():
|
||||||
if software == "pleroma":
|
if software == "pleroma":
|
||||||
@ -50,7 +54,7 @@ for blocker, software in c.fetchall():
|
|||||||
try:
|
try:
|
||||||
# Blocks
|
# Blocks
|
||||||
c.execute("delete from blocks where blocker = ?", (blocker,))
|
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"]:
|
if "mrf_simple" in json["metadata"]["federation"]:
|
||||||
for mrf in json["metadata"]["federation"]["mrf_simple"]:
|
for mrf in json["metadata"]["federation"]["mrf_simple"]:
|
||||||
for blocked in json["metadata"]["federation"]["mrf_simple"][mrf]:
|
for blocked in json["metadata"]["federation"]["mrf_simple"][mrf]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user