From 3a54a74443b373745bcf162d10e4dd67d50d1f14 Mon Sep 17 00:00:00 2001 From: kthouky Date: Wed, 9 Aug 2023 16:20:10 +0200 Subject: [PATCH] fix: update_blacklist.py now uses pythonseer --- README.md | 6 +++++- examples/requirements.txt | 1 + examples/update_blacklist.py | 20 ++++++++++++++------ fediseer/apis/v1/whitelist.py | 2 +- fediseer/templates/index.md | 6 +++++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b61069b..de71a28 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ The currently running instance is on https://fediseer.com See devlog: https://dbzer0.com/blog/overseer-a-fediverse-chain-of-trust/ +# Libraries + +We provide a Python library to interact programmatically with the fediseer api: [Pythonseer](https://github.com/db0/pythonseer) + # Badges You can retrieve and display a badge for your fediverse domain by requesting a .svg for it on a special endpoint @@ -26,4 +30,4 @@ Example: [![](http://fediseer.com/api/v1/badges/endorsements/lemmy.dbzer0.com.sv ```markdown [![](http://fediseer.com/api/v1/badges/endorsements/lemmy.dbzer0.com.svg)](https://fediseer.com/api/v1/endorsements/lemmy.dbzer0.com)` -``` \ No newline at end of file +``` diff --git a/examples/requirements.txt b/examples/requirements.txt index 2dc314d..d6d0f0c 100644 --- a/examples/requirements.txt +++ b/examples/requirements.txt @@ -1,2 +1,3 @@ requests pythorhead +pythonseer diff --git a/examples/update_blacklist.py b/examples/update_blacklist.py index 86a8bda..12d637b 100644 --- a/examples/update_blacklist.py +++ b/examples/update_blacklist.py @@ -1,6 +1,8 @@ import requests from pythorhead import Lemmy +from pythonseer import Fediseer +from pythonseer.types import FormatType # Your own instance's domain LEMMY_DOMAIN = "lemmy.dbzer0.com" @@ -13,8 +15,7 @@ MONTHLY_ACTIVITY_SUSPICION = 500 # Extra domains you can block. You can just delete the contents if you want to only block suspicious domains blacklist = { "truthsocial.com", - "exploding-heads.com", - "lemmygrad.ml", + "threads.net", } @@ -22,11 +23,18 @@ lemmy = Lemmy(f"https://{LEMMY_DOMAIN}") if lemmy.log_in(USERNAME, PASSWORD) is False: raise Exception("Could not log in to lemmy") +fediseer = Fediseer() print("Fetching suspicions") -sus = requests.get(f"https://fediseer.com/api/v1/instances?activity_suspicion={ACTIVITY_SUSPICION}&active_suspicion={MONTHLY_ACTIVITY_SUSPICION}&domains=true", timeout=5).json() -defed = blacklist | set(sus["domains"]) +sus = fediseer.suspicions.get( + activity_suspicion=ACTIVITY_SUSPICION, + active_suspicion=MONTHLY_ACTIVITY_SUSPICION, + format=FormatType.LIST +) +print("Fetching censures") +censures = fediseer.censure.get_given(LEMMY_DOMAIN, FormatType.LIST) +defed = blacklist | set(censures["domains"]) | set(sus["domains"]) # I need to retrieve the site info because it seems if "RequireApplication" is set -# We need to always re-set the application_question. +# We need to always re-set the application_question. # So we retrieve it from the existing site, to set the same value site = lemmy.site.get() application_question = None @@ -42,4 +50,4 @@ else: ret = lemmy.site.edit( blocked_instances=list(defed), ) -print("Edit Successful") \ No newline at end of file +print("Edit Successful") diff --git a/fediseer/apis/v1/whitelist.py b/fediseer/apis/v1/whitelist.py index bb85c28..6277343 100644 --- a/fediseer/apis/v1/whitelist.py +++ b/fediseer/apis/v1/whitelist.py @@ -127,7 +127,7 @@ class WhitelistDomain(Resource): requestor = user.username instance_to_reset = database.find_instance_by_account(f"@{self.args.regenerate_key}@{domain}") if instance != instance_to_reset and user.username != "fediseer": - raise e.BadRequest("Only other admins or the fediseer can request API key reset for others.") + raise e.BadRequest("Only other admins of the same instance or the fediseer can request API key reset for others.") instance = instance_to_reset user = database.find_user_by_account(f"@{self.args.regenerate_key}@{domain}") new_key = activitypub_pm.pm_new_api_key(domain, self.args.regenerate_key, instance.software, requestor=requestor) diff --git a/fediseer/templates/index.md b/fediseer/templates/index.md index 6cf1329..5d287f4 100644 --- a/fediseer/templates/index.md +++ b/fediseer/templates/index.md @@ -4,7 +4,7 @@ This is a [FOSS service](https://github.com/db0/fediseer) to help Fediverse inst [What is Fediseer](https://dbzer0.com/blog/overseer-a-fediverse-chain-of-trust/) devlog -## Scope +## Scope This Fediseer is focused around anti-spam verification. We make no judgement on the content of the guaranteed communities other than they have been verified to not be fake spam instances and are making a good effort to block spam accounts. @@ -14,6 +14,10 @@ However using the endorsement system, you can create a further customized whitel [Full API Documentation](/api/) +## Libraries + +* [Pythonseer](https://github.com/db0/pythonseer) (Python) + ## Community * [Fediverse Community](https://lemmy.dbzer0.com/c/fediseer)