diff --git a/examples/requirements.txt b/examples/requirements.txt new file mode 100644 index 0000000..2dc314d --- /dev/null +++ b/examples/requirements.txt @@ -0,0 +1,2 @@ +requests +pythorhead diff --git a/examples/update_blacklist.py b/examples/update_blacklist.py new file mode 100644 index 0000000..3bd6ee1 --- /dev/null +++ b/examples/update_blacklist.py @@ -0,0 +1,28 @@ +import requests + +from pythorhead import Lemmy + +# Your own instance's domain +LEMMY_DOMAIN = "lemmy.dbzer0.com" +USERNAME = "username" +PASSWORD = "password" +# If there's this many registered users per local post+comments, this site will be considered suspicious +ACTIVITY_SUSPICION = 20 +# 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", +} + + +lemmy = Lemmy(f"https://{LEMMY_DOMAIN}") +if lemmy.log_in(USERNAME, PASSWORD) is False: + raise Exception("Could not log in to lemmy") + +print("Fetching suspicions") +sus = requests.get(f"https://overseer.dbzer0.com/api/v1/instances?activity_suspicion={ACTIVITY_SUSPICION}&domains=true", timeout=5).json() +defed = blacklist | set(sus["domains"]) +print("Editing Defederation list") +ret = lemmy.site.edit(blocked_instances=list(defed)) +print("Edit Successful") \ No newline at end of file