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)
Revision: 5320
Author: nicdumz
Date: 2008-05-07 13:37:59 +0000 (Wed, 07 May 2008)
Log Message:
-----------
* Special:Log has changed. -offset:# is not available anymore, only -offset:TIMESTAMP is (bug #1959384)
* Using Site method to get Special:Log instead of hardcoded value
Modified Paths:
--------------
trunk/pywikipedia/welcome.py
Modified: trunk/pywikipedia/welcome.py
===================================================================
--- trunk/pywikipedia/welcome.py 2008-05-07 10:09:52 UTC (rev 5319)
+++ trunk/pywikipedia/welcome.py 2008-05-07 13:37:59 UTC (rev 5320)
@@ -59,8 +59,11 @@
-limit[:#] Use this parameter to define how may users should be
checked (default:50)
- -offset[:#] Skip the latest # new users to give interactive users
- a chance to welcome the new user (default: 0)
+ -offset[:TIME] Skip the latest new users (those newer than TIME)
+ to give interactive users a chance to welcome the
+ new users (default: now)
+ Timezone is the server timezone, GMT for Wikimedia
+ TIME format : yyyymmddhhmmss
-numberlog[:#] The number of users to welcome before refreshing the
welcome log (default: 4)
@@ -565,9 +568,12 @@
time_variable = int(arg[6:])
elif arg.startswith('-offset'):
if len(arg) == 7:
- offset_variable = int(wikipedia.input(u'Which 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?'))
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.")
elif arg.startswith('-file:'):
random = True
fileOption = True
@@ -748,11 +754,11 @@
say_hi = ("S", "s", "Saluto", "saluto", "Welcome", "welcome", 'w', 'W', 'say hi',
'Say hi', 'Hi', 'hi', 'h', 'hello', 'Hello')
- # The URL for new users is the same in every project. It should not be changed.
- if offset_variable == 0:
- URL = "/w/index.php?title=Special:Log&type=newusers&limit=%d" % limit
- else:
- URL = "/w/index.php?title=Special:Log&type=newusers&limit=%d&offset=%d" % (limit, offset_variable)
+ # think about non-wikimedia wikis. Use Site functions.
+ URL = wsite.log_address(limit, 'newusers')
+ 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
Bugs item #1959384, was opened at 2008-05-07 11:56
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1959384&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: DarkoNeko (darkoneko)
Assigned to: Nobody/Anonymous (nobody)
Summary: welcome.py seems to ignore offset
Initial Comment:
Version used:
5318 (latest available, since I did an update just before re-testing the bug)
Command used :
/usr/bin/python ~/pywikipedia/welcome.py -nlog -limit:300 -offset:40 -random -time:300
Problem :
the script ignores offset and welcomes users since the first one (verified using http://fr.wikipedia.org/wiki/Special:log/newusers )
I thought the problem was "it ignores the 40 first lines, regardless of what action it is" but it's not the case : the welcomed user (Yusukay) was 6th in user creation list, and 27th in the overall log.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1959384&group_…
I have modified solve_disambiguation.py in order it leaves a notice on
user's talk page if a subpage of his/hers has been edited by the
disambiguation robot. Main idea was that on subpages there are very often
articles under construction, and correcting the links in them should be in
accordance with the author's purpose. I never edit the userpage itself, only
subpages, if this seems to be the owner's purpose.
Is anybody interested in publication of such a code? This stands after
modifying refPage:
if refPage.namespace()==2:
UserSubPage=refPage.titleWithoutNamespace()
try:
UserPage=UserSubPage[:UserSubPage.index('/')]
except ValueError:
UserPage=UserSubPage
UserTalkPage='User vita:'+UserPage
wikipedia.output(UserTalkPage)
EditComment = u"Figyelmeztetés felhasználói allap változtatására"
WarnText=u'\n==Egyértelműsítés felhasználói allapon==\n'
WarnText+=u'A(z) [[%s]] lapon módosítottam egy (vagy több)
hivatkozást, amely a(z) [[%s]] egyértelműsítő lapra mutatott.
[[User:BinBot#Egyértelműsítési irányelvek|Szívből remélem]], hogy ez
megfelelt a szándékaidnak. Ha nem, akkor [[user vita:Bináris|a gazdám
nevében]] elnézést kérek. ~~~~' % (refPage.title() , disambPage.title())
site=wikipedia.getSite()
page = wikipedia.Page(site, UserTalkPage)
page.put(page.get()+WarnText, EditComment,
minorEdit=False)
#TODO:
# - to put the notification into a try/except
# - to translate the texts and internationalizing them if
there is any attention to make this utility public
I am not familiar with Sourceforge methods, that's why I tell you here. I
need help in publication, but I don't mind if nobody is interested in doing
that, becuse I wrote it for myself.
--
Bináris
Bugs item #1958645, was opened at 2008-05-06 13:13
Message generated for change (Comment added) made by nicdumz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1958645&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: interwiki
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Hugo.arg (hugoarg)
Assigned to: Nobody/Anonymous (nobody)
Summary: Translations 2
Initial Comment:
Some more translations for interwiki.py
Normand
'nrm': (u'robot ', u'ajouôte', u'hale', u'amende'),
Dhivehi
'dv': (u'ރޮބޮޓ ', u'އިތުރު ކުރުނ', u'ފޮހެލުނ', u'ބަދަލު ގެނައުނ'),
Maori
'mi': (u'he karetao ', u'e tāpiri ana', u'e tango ana', u'e whakarerekē ana'),
Modifiyed Albanian version:
'sq': (u'roboti ', u'shtoj', u'largoj', u'ndryshoj'),
Thank you :)
----------------------------------------------------------------------
Comment By: NicDumZ — Nicolas Dumazet (nicdumz)
Date: 2008-05-06 14:12
Message:
Logged In: YES
user_id=1963242
Originator: NO
added in r5316. Thanks ! :)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1958645&group_…
Bugs item #1958645, was opened at 2008-05-06 14:13
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1958645&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: interwiki
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Hugo.arg (hugoarg)
Assigned to: Nobody/Anonymous (nobody)
Summary: Translations 2
Initial Comment:
Some more translations for interwiki.py
Normand
'nrm': (u'robot ', u'ajouôte', u'hale', u'amende'),
Dhivehi
'dv': (u'ރޮބޮޓ ', u'އިތުރު ކުރުނ', u'ފޮހެލުނ', u'ބަދަލު ގެނައުނ'),
Maori
'mi': (u'he karetao ', u'e tāpiri ana', u'e tango ana', u'e whakarerekē ana'),
Modifiyed Albanian version:
'sq': (u'roboti ', u'shtoj', u'largoj', u'ndryshoj'),
Thank you :)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1958645&group_…