jenkins-bot merged this change.
[IMPR] Move skipping conditions into skip_page in welcome.py
- Move skipping conditions into skip_page and reduce code complexity
of run method a lot.
- skip_page method can be easily reused when run method is changed to treat
detached from Iff53f38
Change-Id: If3641e2ab4c851fd3f957f46680dfa3bef9b2040
---
M scripts/welcome.py
1 file changed, 37 insertions(+), 27 deletions(-)
diff --git a/scripts/welcome.py b/scripts/welcome.py
index a2335a8..add95e9 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -777,26 +777,48 @@
self._randomSignature = creg.findall(sign_text)
return self._randomSignature
+ def skip_page(self, users):
+ """Check whether the user is to be skipped."""
+ if users.isBlocked():
+ showStatus(3)
+ pywikibot.output('{} has been blocked!'
+ .format(users.username))
+
+ elif 'bot' in users.groups():
+ showStatus(3)
+ pywikibot.output('{} is a bot!'
+ .format(users.username))
+
+ elif 'bot' in users.username.lower():
+ showStatus(3)
+ pywikibot.output('{} might be a global bot!'
+ .format(users.username))
+
+ elif users.editCount() == 0:
+ if not globalvar.quiet:
+ showStatus(1)
+ pywikibot.output('{} has no contributions.'
+ .format(users.username))
+
+ elif users.editCount() < globalvar.attachEditCount:
+ showStatus(1)
+ pywikibot.output('{0} has only {1} contributions.'
+ .format(users.username,
+ users.editCount()))
+
+ else:
+ return super(WelcomeBot, self).skip_page(users)
+
+ return True
+
def run(self):
"""Run the bot."""
while True:
welcomed_count = 0
for users in self.parseNewUserLog():
- if users.isBlocked():
- showStatus(3)
- pywikibot.output('{} has been blocked!'
- .format(users.username))
+ if self.skip_page(users):
continue
- if 'bot' in users.groups():
- showStatus(3)
- pywikibot.output('{} is a bot!'
- .format(users.username))
- continue
- if 'bot' in users.username.lower():
- showStatus(3)
- pywikibot.output('{} might be a global bot!'
- .format(users.username))
- continue
+
if users.editCount() >= globalvar.attachEditCount:
showStatus(2)
pywikibot.output('{} has enough edits to be welcomed.'
@@ -854,19 +876,7 @@
else:
continue
# If we haven't to report, do nothing.
- else:
- if users.editCount() == 0:
- if not globalvar.quiet:
- showStatus(1)
- pywikibot.output('{} has no contributions.'
- .format(users.username))
- else:
- showStatus(1)
- pywikibot.output('{0} has only {1} contributions.'
- .format(users.username,
- users.editCount()))
- # That user mustn't be welcomed.
- continue
+
if globalvar.makeWelcomeLog and welcomed_count > 0:
showStatus()
if welcomed_count == 1:
To view, visit change 508516. To unsubscribe, or for help writing mail filters, visit settings.