[Pywikipedia-l] SVN: [5321] trunk/pywikipedia
nicdumz at svn.wikimedia.org
nicdumz at svn.wikimedia.org
Wed May 7 14:45:05 UTC 2008
Revision: 5321
Author: nicdumz
Date: 2008-05-07 14:45:04 +0000 (Wed, 07 May 2008)
Log Message:
-----------
Adding a relative time offset to welcome.py
This includes adding in Family and Site the method server_time() returning a datetime representing the servertime (currently based on a per site configured offset, using the user system clock)
Modified Paths:
--------------
trunk/pywikipedia/family.py
trunk/pywikipedia/welcome.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/family.py
===================================================================
--- trunk/pywikipedia/family.py 2008-05-07 13:37:59 UTC (rev 5320)
+++ trunk/pywikipedia/family.py 2008-05-07 14:45:04 UTC (rev 5321)
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import config, urllib, re
+from datetime import timedelta, datetime
__version__='$Id$'
@@ -39,6 +40,11 @@
]
self.langs = {}
+
+ # The timedelta to GMT of the server.
+ # Exemple for a server running CET :
+ # timedelta(hours=+1)
+ self.servergmtoffset = timedelta()
# Translation used on all wikis for the different namespaces.
# (Please sort languages alphabetically)
@@ -3051,3 +3057,8 @@
def shared_image_repository(self, code):
"""Return the shared image repository, if any."""
return (None, None)
+
+ def server_time(self):
+ """Returns a datetime object representing server time"""
+ # TODO : If the local computer time is wrong, result wll be wrong
+ return datetime.utcnow() + self.servergmtoffset
Modified: trunk/pywikipedia/welcome.py
===================================================================
--- trunk/pywikipedia/welcome.py 2008-05-07 13:37:59 UTC (rev 5320)
+++ trunk/pywikipedia/welcome.py 2008-05-07 14:45:04 UTC (rev 5321)
@@ -65,6 +65,9 @@
Timezone is the server timezone, GMT for Wikimedia
TIME format : yyyymmddhhmmss
+ -timeoffset[:#] Skip the latest new users, accounts newer than
+ # minutes
+
-numberlog[:#] The number of users to welcome before refreshing the
welcome log (default: 4)
@@ -171,6 +174,7 @@
import wikipedia, config, string, locale
import time, re, cPickle, os, urllib
import codecs, sys
+from datetime import timedelta
locale.setlocale(locale.LC_ALL, '')
@@ -542,7 +546,8 @@
number = 1 # number of edits that an user required to be welcomed
numberlog = 15 # number of users that are required to add the log :)
limit = 50 # number of users that the bot load to check
- offset_variable = 0 # number of newest users to skip each run
+ offset_variable = 0 # skip users newer than that timestamp
+ timeoffset_variable = 0 # skip users newer than # minutes
recursive = True # define if the Bot is recursive or not
time_variable = 3600 # how much time (sec.) the bot sleeps before restart
log_variable = True # create the welcome log or not
@@ -561,6 +566,11 @@
number = int(wikipedia.input(u'After how many edits would you like to welcome new users? (0 is allowed)'))
else:
number = int(arg[6:])
+ elif arg.startswith('-timeoffset'):
+ if len(arg) == 11:
+ timeoffset_variable = int(wikipedia.input(u'Which time offset (in minutest) for new users would you like to use?'))
+ else:
+ timeoffset_variable = int(arg[12:])
elif arg.startswith('-time'):
if len(arg) == 5:
time_variable = int(wikipedia.input(u'For how many seconds would you like to bot to sleep before checking again?'))
@@ -568,12 +578,12 @@
time_variable = int(arg[6:])
elif arg.startswith('-offset'):
if len(arg) == 7:
- offset_variable = int(wikipedia.input(u'Which time offset for new users would you like to use?'))
+ offset_variable = int(wikipedia.input(u'Which time offset for new users would you like to use? (yyyymmddhhmmss)'))
else:
offset_variable = int(arg[8:])
if len(str(offset_variable)) != 14:
# upon request, we might want to check for software version here
- raise ValueError("Mediawiki has changed, -offset:# is not supported anymore, but -offset:TIMESTAMP is, assuming TIMESTAMP is yyyymmddhhmmss. Please read this script source header for documentation.")
+ raise ValueError("Mediawiki has changed, -offset:# is not supported anymore, but -offset:TIMESTAMP is, assuming TIMESTAMP is yyyymmddhhmmss. -timeoffset is now also supported. Please read this script source header for documentation.")
elif arg.startswith('-file:'):
random = True
fileOption = True
@@ -606,8 +616,11 @@
# TODO: Maybe it's better change the tuple with a dictionary..
wsite = wikipedia.getSite()
filename = 'welcome-%s-%s.data' % (wsite.family.name, wsite.lang) # file where is stored the random signature index
+ if offset_variable and timeoffset_variable:
+ wikipedia.output('WARING: both -offset and -timeoffset were provided, ignoring -offset')
+ offset_variable = 0
return (None, ask, filename, fileOption, fileSignName, filter_wp, limit, log_variable, number, numberlog, offset_variable, random, recursive,
- savedata, sign, time_variable)
+ savedata, sign, time_variable, timeoffset_variable)
def main(settingsBot):
# Taking the messages inside the function namespace.
@@ -636,6 +649,7 @@
savedata = settingsBot[13]
sign = settingsBot[14]
time_variable = settingsBot[15]
+ timeoffset_variable = settingsBot[16]
# The site
wsite = wikipedia.getSite()
@@ -756,9 +770,11 @@
# think about non-wikimedia wikis. Use Site functions.
URL = wsite.log_address(limit, 'newusers')
+ if timeoffset_variable != 0:
+ time = wsite.server_time() - timedelta(minutes=timeoffset_variable)
+ offset_variable = int(time.strftime("%Y%m%d%H%M%S"))
if offset_variable != 0:
URL += "&offset=%d" % offset_variable
- print URL
log = wsite.getUrl(URL)
wikipedia.output(u'Loading latest %s new users from %s...\n' % (limit, wsite.hostname()))
# Determine which signature to use
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2008-05-07 13:37:59 UTC (rev 5320)
+++ trunk/pywikipedia/wikipedia.py 2008-05-07 14:45:04 UTC (rev 5321)
@@ -3766,6 +3766,7 @@
versionnumber: Return int identifying the MediaWiki version.
live_version: Return version number read from Special:Version.
checkCharset(charset): Warn if charset doesn't match family file.
+ server_time : returns server time (currently userclock depending)
linktrail: Return regex for trailing chars displayed as part of a link.
disambcategory: Category in which disambiguation pages are listed.
@@ -3975,6 +3976,11 @@
index = self._userIndex(sysop)
return right in self._rights[index]
+ def server_time(self):
+ """returns a datetime object representing server time"""
+ # It is currently user-clock depending
+ return self.family.get_server_time()
+
def messages(self, sysop = False):
"""Returns true if the user has new messages, and false otherwise."""
self._load(sysop = sysop)
More information about the Pywikipedia-l
mailing list