User:Surjection/inactive sysops.py
Jump to navigation
Jump to search
from pywikibot import Site, Page, Category, Timestamp from datetime import datetime, timedelta "removal of admin rights without prejudice (i.e. returnable upon request) [[Wiktionary:Administrators#Removal for inactivity|due to inactivity]] (no admin tools used in the past five years)" """ == Admin rights == Hi, I have removed your admin rights due to [[Wiktionary:Administrators#Removal for inactivity|our policy on admin inactivity]], as you have not used any admin tools in the past five years. This removal is without prejudice and you can request your admin rights to be restored at any time. ~~~~ """ enwikt = Site("en", fam="wiktionary") enwikt.login() now = datetime.now() cutoff = now.replace(year=now.year - 5) cutoff_iso = cutoff.isoformat() cutoff_ts = Timestamp.fromISOformat(cutoff_iso) print("Cutoff:", cutoff_ts) DEBUG = True CONTRIB_UPPER_LIMIT = 10000 admins = [admin['name'] for admin in enwikt.allusers(group='sysop')] for username in admins: if username in {"Abuse filter"}: # never active, that nerd continue def is_active(username): for event in enwikt.logevents(user=username, end=cutoff_ts): action = event.action() if "abusefilter" in action: if DEBUG: print(username.ljust(50) + "modified abuse filters") return True if action in {"block", "reblock", "unblock", # self-explanatory "delete", "restore", # page (un)deletion "protect", "unprotect", "modify", # page (un)protection or modifying a protection "event", # deletion of log events "revision", # revision (un)deletion "rights" # changing of user rights }: if DEBUG: print(username.ljust(50) + "performed admin action {}".format(action)) return True if action in {"move", "move_redir"} and event.suppressedredirect(): if DEBUG: print(username.ljust(50) + "moved page without redirect") return True for contribs, page in enumerate(enwikt.preloadpages(Page(enwikt, edit["title"]) for edit in enwikt.usercontribs(user=username, end=cutoff_ts))): if contribs > CONTRIB_UPPER_LIMIT: if DEBUG: print(username.ljust(50) + "has been an active contributor") return True try: if page.ns in {8}: if DEBUG: print(username.ljust(50) + "edited a system message [[{}]]".format(page.title())) return True except AttributeError: continue if page.protection().get('edit', None): if page.protection().get('edit', None) != 'autoconfirmed': if DEBUG: print(username.ljust(50) + "edited a protected page [[{}]]".format(page.title())) return True return False if not is_active(username): print(username)