204
Deleting >4000 junk communities by @LMAO
(lemmy.sdf.org)
I recently wrote a command-line utility lemmyverse to find communities indexed by Lemmy Explorer. A quick count shows almost 14%(!) of all communities indexed by lemmyverse are junk communities created by a single user @LMAO (reported here):
% lemmyverse . | wc -l
30376
% lemmyverse enoweiooe | wc -l
4206
Here's a python script, using no external dependencies, which uses Lemmy's HTTP API to delete all communities that @LMAO moderates:
#!/usr/bin/env python
import json
import urllib.parse
import urllib.request
baseurl = "https://lemmy.world"
username = "admin"
password = "password"
def login(user, passwd):
url = baseurl+"/api/v3/user/login"
body = urllib.parse.urlencode({
"username_or_email": user,
"password": passwd,
})
resp = urllib.request.urlopen(url, body.encode())
j = json.load(resp)
return j["jwt"]
def get_user(name):
query = urllib.parse.urlencode({"username": name})
resp = urllib.request.urlopen(baseurl+"/api/v3/user?"+query)
return json.load(resp)
def delete_community(token, id):
url = baseurl+"/api/v3/community/delete"
params = {
"auth": token,
"community_id": id,
}
body = urllib.parse.urlencode(params)
urllib.request.urlopen(url, body.encode())
token = login(username, password)
user = get_user("LMAO")
for community in user["moderates"]:
id = community["community"]["id"]
try:
delete_community(token, id)
except Exception as err:
print("delete community id %d: %s" % (id, err))
Change username
and password
on lines 8 and 9 to suit.
Hope that helps! :) Thanks for the work you all put in to running this popular instance.
Yup, that's the guy, says so in the profile bio.