Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312031

Change subject: [IMPR] Implement missing options behaviours
......................................................................

[IMPR] Implement missing options behaviours

- implement -offset option but test the Timestamp instead of the string length
- implement -timeoffset option
- implemet -sul option. parseNewUserLog generator retrieves
  pywikibot.User items instead of logEntry objects.
  Only yield 'create' actions or when -sul is given 'autocreate' too.
  Other action result are skipped.
- Fix doc for L10N dict lists. Some of them are replaced by i18n from twn.

Change-Id: I26c76aa64ef934116756804986555db62bb64317
---
M scripts/welcome.py
1 file changed, 21 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/31/312031/1

diff --git a/scripts/welcome.py b/scripts/welcome.py
index f3d9957..9c2d3ba 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -176,6 +176,7 @@
 #
 
 import codecs
+from datetime import timedelta
 import locale
 import re
 import sys
@@ -199,8 +200,8 @@
 # been eliminated.
 # FIXME: Not all language/project combinations have been defined yet.
 #        Add the following strings to customise for a language:
-#        logbook, talk_page, netext, user, con, report_page
-#        bad_pag, report_text, logt, random_sign and whitelist_pg.
+#        logbook, netext, report_page, bad_pag, report_text, random_sign,
+#        whitelist_pg, final_new_text_additions, logpage_header
 
 ############################################################################
 
@@ -411,7 +412,7 @@
 
     attachEditCount = 1     # number of edits that an user required to be 
welcomed
     dumpToLog = 15          # number of users that are required to add the log 
:)
-    offset = 0              # skip users newer than that timestamp
+    offset = None           # skip users newer than that timestamp
     timeoffset = 0          # skip users newer than # minutes
     recursive = True        # define if the Bot is recursive or not
     timeRecur = 3600        # how much time (sec.) the bot sleeps before 
restart
@@ -663,8 +664,17 @@
                 time.sleep(10)
 
     def parseNewUserLog(self):
-        """Retrieve ne users."""
-        return self.site.logevents('newusers', total=globalvar.queryLimit)
+        """Retrieve new users."""
+        if globalvar.timeoffset != 0:
+            start = self.site.server_time() - timedelta(
+                minutes=globalvar.timeoffset)
+        else:
+            start = globalvar.offset
+        for ue in self.site.logevents('newusers', total=globalvar.queryLimit,
+                                      start=start):
+            if ue.action == 'create' or (
+                    ue.action == 'autocreate' and globalvar.welcomeAuto):
+                yield pywikibot.User(ue.page())
 
     def defineSign(self, force=False):
         """Setup signature."""
@@ -712,9 +722,7 @@
         """Run the bot."""
         while True:
             welcomed_count = 0
-            us = (pywikibot.User(self.site, users.user())
-                  for users in self.parseNewUserLog())
-            for users in us:
+            for users in self.parseNewUserLog():
                 if users.isBlocked():
                     showStatus(3)
                     pywikibot.output(u'%s has been blocked!' % users.name())
@@ -905,11 +913,13 @@
                 globalvar.timeRecur = int(arg[6:])
         elif arg.startswith('-offset'):
             if len(arg) == 7:
-                globalvar.offset = int(pywikibot.input(
+                val = int(pywikibot.input(
                     u'Which time offset for new users would you like to use? 
(yyyymmddhhmmss)'))
             else:
-                globalvar.offset = int(arg[8:])
-            if len(str(globalvar.offset)) != 14:
+                val = arg[8:]
+            try:
+                globalvar.offset = pywikibot.Timestamp.fromtimestampformat(val)
+            except ValueError
                 # upon request, we might want to check for software version 
here
                 raise ValueError(
                     "Mediawiki has changed, -offset:# is not supported "

-- 
To view, visit https://gerrit.wikimedia.org/r/312031
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I26c76aa64ef934116756804986555db62bb64317
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to