Skip to content

Commit 04b81ec

Browse files
committed
Made RemoveBase compatible with trials
1 parent dfd75d6 commit 04b81ec

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

RemoveBase.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class RemoveBase:
7-
def __init__(self, log_name, category):
7+
def __init__(self, log_name, category, trial = False):
88
self.pattern = r'(?:User talk:)([^/\n]+)'
99
self.site = pywikibot.Site() # fam="wikipedia", code="en", user="TheSandBot")
1010
self.count = 0
@@ -16,6 +16,7 @@ def __init__(self, log_name, category):
1616
print("\nBad category title")
1717
exit()
1818
self.cat_name = category
19+
self.trial = trial
1920

2021
def category_remove(self, target: str, page: pywikibot.Page) -> None:
2122
"""
@@ -49,38 +50,52 @@ def log(self, page):
4950

5051

5152
class RemoveBlocked(RemoveBase):
52-
def __init__(self, log_name, category, target, brfa):
53-
super(RemoveBlocked, self).__init__(log_name, category)
53+
def __init__(self, log_name, category, target, brfa, trial=False, count=50):
54+
super(RemoveBlocked, self).__init__(log_name, category, trial)
5455
self.target = target
5556
self.brfa = brfa
57+
if trial:
58+
self.count = count
5659

5760
def run(self):
61+
counter = 0
5862
for page in self.category:
5963
if page.title() == "Template:Uw-corpname":
6064
continue
61-
user = self.generate_user(page)
62-
65+
if counter >= self.count:
66+
print("\n\nDONE TRIAL\n\n")
67+
return
68+
try:
69+
user = self.generate_user(page)
70+
except AttributeError:
71+
print("Failed" + page.title())
72+
continue
73+
summary = "Removing [[Category:" + self.cat_name + "]] as user is "
6374
if self.isLocked(user.username):
6475
self.log(page)
6576
self.category_remove(self.target, page)
6677
page.save(
67-
summary="Removing " + self.cat_name + " as user is locked." +
78+
summary=summary + "locked." +
6879
" ([[Wikipedia:Bots/Requests for approval/" + self.brfa + "|BRFA]])", minor=True,
6980
botflag=True, force=True)
7081
print("Saved " + str(page.title()))
82+
if self.trial:
83+
counter += 1
7184
elif user.isBlocked():
7285
self.log(page)
7386
self.category_remove(self.target, page)
7487
page.save(
75-
summary="Removing " + self.cat_name + " as user is blocked." +
88+
summary=summary + "blocked." +
7689
" ([[Wikipedia:Bots/Requests for approval/" + self.brfa + "|BRFA]])", minor=True,
7790
botflag=True, force=True)
7891
print("Saved " + str(page.title()))
92+
if self.trial:
93+
counter += 1
7994

8095

8196
class RemoveUnblocked(RemoveBase):
82-
def __init__(self, log_name, category, target, backup_target, brfa):
83-
super(RemoveUnblocked, self).__init__(log_name, category)
97+
def __init__(self, log_name, category, target, backup_target, brfa, trial = False):
98+
super(RemoveUnblocked, self).__init__(log_name, category, trial)
8499
self.target = target
85100
self.backup_target = backup_target
86101
self.brfa = brfa
@@ -102,7 +117,7 @@ def run(self):
102117
print("Move to backup")
103118
self.category_remove(self.backup_target, page)
104119
page.save(
105-
summary="Removing " + self.cat_name + " as user is unblocked." +
120+
summary="Removing [[Category:" + self.cat_name + "]] as user is unblocked." +
106121
" ([[Wikipedia:Bots/Requests for approval/" + self.brfa + "|BRFA]])", minor=True,
107122
botflag=True, force=True)
108123
print("Saved " + str(page.title()))

analysis/bot_username_blocks.py

Whitespace-only changes.

remove_blocked.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)