Revision: 7952
Author: xqt
Date: 2010-02-23 11:33:54 +0000 (Tue, 23 Feb 2010)
Log Message:
-----------
* Documentation for TEMPLATE_PAGE
* enable a language code to work on
* take month names from mediawiki if locale.nl_langinfo is not availlable
* additional regexes needed for other languages
* ignore time.tzset() if it's not availlable (bug #1844769)
Modified Paths:
--------------
trunk/pywikipedia/archivebot.py
Modified: trunk/pywikipedia/archivebot.py
===================================================================
--- trunk/pywikipedia/archivebot.py 2010-02-22 21:26:53 UTC (rev 7951)
+++ trunk/pywikipedia/archivebot.py 2010-02-23 11:33:54 UTC (rev 7952)
@@ -15,6 +15,44 @@
either basing on the thread's name or then name can contain a counter which
will be incremented when the archive reaches a certain size.
+Trancluded template may contain the following parameters:
+
+{{TEMPLATE_PAGE
+|archive =
+|algo =
+|counter =
+|maxarchivesize =
+|minthreadsleft =
+|minthreadstoarchive =
+|archiveheader =
+|key =
+}}
+
+Meanings of parameters are:
+
+archive Name of the page to which archived threads will be put.
+ Must be a subpage of the current page. Variables are
+ supported.
+algo specifies the maximum age of a thread. Must be in the form
+ old(<delay>) where <delay> specifies the age in hours or
+ days like 24h or 5d.
+ Default ist old(24h)
+counter The current value of a counter which could be assigned as
+ variable. Will be actualized by bot. Initial value is 1.
+maxarchivesize The maximum archive size before incrementing the counter.
+ Value can be given with appending letter like K or M which
+ indicates KByte or MByte. Default value is 1000M.
+minthreadsleft Minimum number of threads that should be left on a page.
+ Default value is 5.
+minthreadstoarchive The minimum number of threads to archive at once. Default
+ value is 2.
+archiveheader Content that will be put on new archive pages as the
+ header. This parameter supports the use of variables.
+ Default value is {{talkarchive}}
+key A secret key that (if valid) allows archives to not be
+ subpages of the page being archived.
+
+
Options:
-h, --help show this help message and exit
-f FILE, --file=FILE load list of pages from FILE
@@ -26,6 +64,7 @@
-c PAGE, --calc=PAGE calculate key for PAGE and exit
-l LOCALE, --locale=LOCALE
switch to locale LOCALE
+ -L LANG, --lang=LANG set the language code to work on
"""
#
# (C) Misza13, 2006-2007
@@ -182,12 +221,18 @@
def int2month(num):
"""Returns the locale's full name of month 'num' (1-12)."""
- return locale.nl_langinfo(locale.MON_1+num-1).decode('utf-8')
+ if hasattr(locale, 'nl_langinfo'):
+ return locale.nl_langinfo(locale.MON_1+num-1).decode('utf-8')
+ Months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']
+ return Site.mediawiki_message(Months[num-1])
def int2month_short(num):
"""Returns the locale's abbreviated name of month 'num' (1-12)."""
- return locale.nl_langinfo(locale.ABMON_1+num-1).replace('\xa0', '').decode('utf-8')
+ if hasattr(locale, 'nl_langinfo'):
+ return locale.nl_langinfo(locale.ABMON_1+num-1).replace('\xa0', '').decode('utf-8')
+ Months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
+ return Site.mediawiki_message(Months[num-1])
def txt2timestamp(txt, format):
@@ -267,7 +312,11 @@
TM = re.search(r'(\d\d?)\. (\S+) (\d\d\d\d) kl\.\W*(\d\d):(\d\d) \(.*?\)', line)
#3. joulukuuta 2008 kello 16.26 (EET)
if not TM:
- TM = re.search(r'(\d\d?)\. (\S+) (\d\d\d\d) kello \W*(\d\d).(\d\d) \(.*?\)', line)
+ TM = re.search(r'(\d\d?)\. (\S+) (\d\d\d\d) kello \W*(\d\d).(\d\d) \(.*?\)', line)
+ if not TM:
+# 14:23, 12. Jan. 2009 (UTC)
+ pat = re.compile(r'(\d\d):(\d\d), (\d\d?)\. (\S+)\.? (\d\d\d\d) \(UTC\)')
+ TM = pat.search(line)
if TM:
# wikipedia.output(TM)
TIME = txt2timestamp(TM.group(0),"%d. %b %Y kl. %H:%M (%Z)")
@@ -287,6 +336,8 @@
TIME = txt2timestamp(TM.group(0),"%H:%M, %b %d, %Y (%Z)")
if not TIME:
TIME = txt2timestamp(TM.group(0),"%d. %Bta %Y kello %H.%M (%Z)")
+ if not TIME:
+ TIME = txt2timestamp(TM.group(0),"%H:%M, %d. %b. %Y (%Z)")
if TIME:
self.timestamp = max(self.timestamp,time.mktime(TIME))
# wikipedia.output(u'Time to be parsed: %s' % TM.group(0))
@@ -522,6 +573,7 @@
def main():
+ global Site, language
from optparse import OptionParser
parser = OptionParser(usage='usage: %prog [options] [LINKPAGE(s)]')
parser.add_option('-f', '--file', dest='filename',
@@ -538,6 +590,8 @@
help='calculate key for PAGE and exit', metavar='PAGE')
parser.add_option('-l', '--locale', dest='locale',
help='switch to locale LOCALE', metavar='LOCALE')
+ parser.add_option('-L', '--lang', dest='lang',
+ help='current language code', metavar='lang')
parser.add_option('-T', '--timezone', dest='timezone',
help='switch timezone to TIMEZONE', metavar='TIMEZONE')
(options, args) = parser.parse_args()
@@ -548,7 +602,8 @@
if options.timezone:
os.environ['TZ'] = options.timezone
#Or use the preset value
- time.tzset()
+ if hasattr(time, 'tzset'):
+ time.tzset()
if options.calc:
if not options.salt:
@@ -569,6 +624,11 @@
else:
force = False
+ if options.lang:
+ Site = wikipedia.getSite(options.lang)
+ language = Site.language()
+ if wikipedia.debug: print Site
+
for a in args:
pagelist = []
if not options.filename and not options.pagename:
@@ -595,10 +655,12 @@
Archiver.run()
time.sleep(10)
except:
- wikipedia.output(u'Error occured while processing page [[%s]]' % pg.title())
+ wikipedia.output(u'Error occured while processing page %s' % pg.aslink(True))
traceback.print_exc()
if __name__ == '__main__':
- main()
- wikipedia.stopme()
+ try:
+ main()
+ finally:
+ wikipedia.stopme()
Revision: 7951
Author: russblau
Date: 2010-02-22 21:26:53 +0000 (Mon, 22 Feb 2010)
Log Message:
-----------
Removing excessively verbose message in standard mode.
Modified Paths:
--------------
branches/rewrite/pywikibot/login.py
Modified: branches/rewrite/pywikibot/login.py
===================================================================
--- branches/rewrite/pywikibot/login.py 2010-02-22 15:08:46 UTC (rev 7950)
+++ branches/rewrite/pywikibot/login.py 2010-02-22 21:26:53 UTC (rev 7951)
@@ -202,7 +202,7 @@
else:
return False
self.storecookiedata(cookiedata)
- pywikibot.output(u"Should be logged in now")
+ pywikibot.output(u"Should be logged in now", level=pywikibot.VERBOSE)
## # Show a warning according to the local bot policy
## FIXME: disabled due to recursion; need to move this to the Site object after
## login
@@ -224,7 +224,7 @@
sysop = False
logall = False
forceLogin = False
- for arg in pywikibot.handleArgs(*args):
+ for arg in pywikibot.handleArgs(*args):
if arg.startswith("-pass"):
if len(arg) == 5:
password = pywikibot.input(u'Password for all accounts:',