http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10921
Revision: 10921
Author: drtrigon
Date: 2013-01-14 18:57:41 +0000 (Mon, 14 Jan 2013)
Log Message:
-----------
bug fix; changed 'print' to 'output' e.g. because of logger
improvement; some PEP 8
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-01-14 15:58:28 UTC (rev 10920)
+++ trunk/pywikipedia/wikipedia.py 2013-01-14 18:57:41 UTC (rev 10921)
@@ -800,7 +800,7 @@
# I raise a ServerError() yet, but maybe it should be NoPage().
if not textareaFound:
if verbose:
- print pageInfo
+ output(str(pageInfo))
raise ServerError('ServerError: No textarea found in %s' % self)
self.editRestriction = ''
@@ -4278,7 +4278,7 @@
# I raise a ServerError() yet, but maybe it should be NoPage().
if not textareaFound:
if verbose:
- print pageInfo
+ output(str(pageInfo))
raise ServerError('ServerError: No textarea found in %s' % self)
self.editRestriction = ''
@@ -4924,7 +4924,7 @@
pagenames = u'\r\n'.join(pagenames)
if type(pagenames) is not unicode:
output(u'Warning: xmlreader.WikipediaXMLHandler.getData() got non-unicode page names. Please report this.')
- print pagenames
+ output(str(pagenames))
# convert Unicode string to the encoding used on that wiki
pagenames = pagenames.encode(self.site.encoding())
predata = {
@@ -6239,7 +6239,8 @@
try:
text = unicode(text, charset, errors = 'strict')
except UnicodeDecodeError, e:
- print e
+ if verbose:
+ output(e)
output(u'ERROR: Invalid characters found on %s://%s%s, replaced by \\ufffd.'
% (self.protocol(), self.hostname(), address))
# We use error='replace' in case of bad encoding.
@@ -6548,7 +6549,8 @@
if self.versionnumber() > 10:
params['siprop'].extend(['statistics', ])
if key in ['specialpagealiases', 'interwikimap', 'namespacealiases', 'usergroups', ]:
- if verbose: print 'getting huge siprop %s...' % key
+ if verbose:
+ output('getting huge siprop %s...' % key)
params['siprop'] = [key]
#ver 1.13 handle
@@ -6556,7 +6558,8 @@
if key not in ['specialpagealiases', 'interwikimap', 'namespacealiases', 'usergroups', ]:
params['siprop'].extend(['fileextensions', 'rightsinfo', ])
if key in ['magicwords', 'extensions', ]:
- if verbose: print 'getting huge siprop %s...' % key
+ if verbose:
+ output('getting huge siprop %s...' % key)
params['siprop'] = [key]
try:
data = query.GetData(params, self)['query']
@@ -7469,7 +7472,7 @@
get_throttle()
data = query.GetData(params, self)
if verbose:
- print 'DEBUG allpages>>> data.keys()', data.keys()
+ output('DEBUG: allpages>>> data.keys() %s' % data.keys())
if 'warnings' in data:
warning = data['warnings']['allpages']['*']
raise RuntimeError("API query warning: %s" % warning)
@@ -8805,9 +8808,9 @@
text = unicode(text, decoder)
elif type(text) is not unicode:
if verbose and sys.platform != 'win32':
- print "DBG> BUG: Non-unicode (%s) passed to wikipedia.output without decoder!" % type(text)
+ print "DEBUG: > BUG: Non-unicode (%s) passed to wikipedia.output without decoder!" % type(text)
print traceback.print_stack()
- print "DBG> Attempting to recover, but please report this problem"
+ print "DEBUG: > Attempting to recover, but please report this problem"
try:
text = unicode(text, 'utf-8')
except UnicodeDecodeError:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10919
Revision: 10919
Author: xqt
Date: 2013-01-14 14:48:52 +0000 (Mon, 14 Jan 2013)
Log Message:
-----------
add. L10N for de-wiki, some minor changes
Modified Paths:
--------------
trunk/pywikipedia/checkimages.py
Modified: trunk/pywikipedia/checkimages.py
===================================================================
--- trunk/pywikipedia/checkimages.py 2013-01-14 10:53:12 UTC (rev 10918)
+++ trunk/pywikipedia/checkimages.py 2013-01-14 14:48:52 UTC (rev 10919)
@@ -14,7 +14,7 @@
-limit The number of images to check (default: 80)
-commons The Bot will check if an image on Commons has the same name
- and if true it report the image.
+ and if true it reports the image.
-duplicates[:#] Checking if the image has duplicates (if arg, set how many
rollback wait before reporting the image in the report
@@ -404,6 +404,7 @@
# A page where there's a list of template to consider as licenses.
PageWithAllowedTemplates = {
'commons': u'User:Filbot/Allowed templates',
+ 'de': u'Benutzer:Xqbot/Lizenzvorlagen',
'it': u'Progetto:Coordinamento/Immagini/Bot/AllowedTemplates',
'ko': u'User:Kwjbot_IV/AllowedTemplates',
}
@@ -418,10 +419,12 @@
# In this part there are the parameters for the dupe images.
-# Put here the template that you want to put in the image to warn that it's a dupe
-# put __image__ if you want only one image, __images__ if you want the whole list
+# Put here the template that you want to put in the image to warn that it's a
+# dupe. put __image__ if you want only one image, __images__ if you want the
+# whole list
duplicatesText = {
'commons': u'\n{{Dupe|__image__}}',
+ 'de': u'{{NowCommons}}',
'it': u'\n{{Progetto:Coordinamento/Immagini/Bot/Template duplicati|__images__}}',
}
@@ -446,6 +449,7 @@
# Comment used by the bot while it reports the problem in the image
duplicates_comment_image = {
'commons': u'Bot: Tagging dupe file',
+ 'de': u'Bot: Datei liegt auf Commons',
'ar': u'بوت: وسم ملف مكرر',
'it': u'Bot: File doppio, da cancellare',
}
@@ -453,6 +457,7 @@
# Regex to detect the template put in the image's decription to find the dupe
duplicatesRegex = {
'commons': r'\{\{(?:[Tt]emplate:|)(?:[Dd]up(?:licat|)e|[Bb]ad[ _][Nn]ame)[|}]',
+ 'de': r'\{\{[nN](?:C|ow(?: c|[cC])ommons)[\|\}',
'it': r'\{\{(?:[Tt]emplate:|)[Pp]rogetto:[Cc]oordinamento/Immagini/Bot/Template duplicati[|}]',
}
@@ -590,13 +595,10 @@
self.botnick = botnick
botolist.append(botnick)
-
self.botolist = botolist
self.sendemailActive = sendemailActive
- # Inizialize the skip list used below
- self.skip_list = list()
-
+ self.skip_list = []
self.duplicatesReport = duplicatesReport
self.image_namespace = u"File:"
@@ -609,7 +611,6 @@
"""
self.imageName = imageName
- # Defing the image's Page Object
self.image = pywikibot.ImagePage(self.site, self.imageName)
self.timestamp = timestamp
self.uploader = uploader
@@ -617,7 +618,6 @@
def report(self, newtext, image_to_report, notification=None, head=None,
notification2=None, unver=True, commTalk=None, commImage=None):
""" Function to make the reports easier. """
- # Defining some useful variable for next...
self.image_to_report = image_to_report
self.newtext = newtext
self.head = head or u''
@@ -627,19 +627,15 @@
if self.notification:
self.notification = re.sub(r'__botnick__', self.botnick,
notification)
-
if self.notification2:
self.notification2 = re.sub(r'__botnick__', self.botnick,
notification2)
self.commTalk = commTalk
if commImage:
- self.commImage = commImage
- else:
- self.commImage = self.comment
+ self.commImage = commImage or self.comment
- # Ok, done, let's loop.
- while 1:
+ while True:
if unver:
try:
resPutMex = self.tag_image()
@@ -731,8 +727,8 @@
for upBot in upBots:
if upBot[0] == luser:
luser = self.uploadBotChangeFunction(reportPageText, upBot)
- talk_page = pywikibot.Page(self.site, u"%s:%s"
- % (self.site.namespace(3), luser))
+ talk_page = pywikibot.Page(self.site,
+ u"%s:%s" % (self.site.namespace(3), luser))
self.talk_page = talk_page
self.luser = luser
return True
@@ -828,7 +824,6 @@
text = self.site.getUrl(link, no_hostname = True)
results = re.findall(r"""<td valign='top' title='Name'><a href='http://.*?\.org/w/index\.php\?title=(.*?)'>.*?</a></td>""",
text)
-
if results:
for result in results:
wikiPage = pywikibot.ImagePage(self.site, result)
@@ -1471,9 +1466,8 @@
def load(self, raw):
""" Load a list of object from a string using regex. """
- list_loaded = list()
+ list_loaded = []
pos = 0
- load_2 = True
# I search with a regex how many user have not the talk page
# and i put them in a list (i find it more easy and secure)
regl = r"(\"|\')(.*?)\1(?:,|\])"
@@ -1518,7 +1512,7 @@
if normal:
printWithTimeZone(u'Skipping the files uploaded less than %s seconds ago..' % waitTime)
imagesToSkip = 0
- while 1:
+ while True:
loadOtherImages = True # ensure that all the images loaded aren't to skip!
for image in generator:
if normal:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10917
Revision: 10917
Author: saper
Date: 2013-01-14 10:43:29 +0000 (Mon, 14 Jan 2013)
Log Message:
-----------
Don't fail easily when wikipedia.py version cannot be determined
My script fails with:
Traceback (most recent call last):
File "eksport.py", line 4, in <module>
import wikipedia
File "/home/admini/saper/wikipedia/pywikipedia/wikipedia.py", line 8748, in <module>
writeToCommandLogFile()
File "/home/admini/saper/wikipedia/pywikipedia/wikipedia.py", line 8685, in writeToCommandLogFile
% (isoDate, version.getversiondict()['rev'],
File "/home/admini/saper/wikipedia/pywikipedia/pywikibot/version.py", line 43, in getversiondict
if len(version) == 4:
TypeError: object of type 'NoneType' has no len()
The reason is that my scripts reach pywikipedia via sys.path
and are not located in the pywikipedia directory.
This fixes the len(version) == 4 case, since version
can be returned None.
A proper fix to determine wikipedia.py is needed, maybe.
Modified Paths:
--------------
trunk/pywikipedia/pywikibot/version.py
Modified: trunk/pywikipedia/pywikibot/version.py
===================================================================
--- trunk/pywikipedia/pywikibot/version.py 2013-01-14 10:17:17 UTC (rev 10916)
+++ trunk/pywikipedia/pywikibot/version.py 2013-01-14 10:43:29 UTC (rev 10917)
@@ -29,6 +29,11 @@
data['cmp_ver'] = 'n/a'
return '%(tag)s (r%(rev)s, %(date)s, %(cmp_ver)s)' % data
+def unknown_version():
+ """Version cannot be determined"""
+ cache = dict(tag='', rev='-1 (unknown)', date='0 (unknown)')
+ return cache
+
def getversiondict():
global cache
if cache:
@@ -40,16 +45,18 @@
(tag, rev, date) = getversion_nightly()
except Exception, e:
version = getfileversion('wikipedia.py')
- if len(version) == 4:
- # the value is most likely '$Id' + '$', it means that
- # wikipedia.py got imported without using svn at all
- cache = dict(tag='', rev='-1 (unknown)', date='0 (unknown)')
- return cache
-
- id, file, rev, date, ts, author, dollar = version.split(' ')
- tag = ''
- date = time.strptime('%sT%s' % (date, ts), '%Y-%m-%dT%H:%M:%SZ')
- rev += ' (wikipedia.py)'
+ if version:
+ try:
+ id, file, rev, date, ts, author, dollar = version.split(' ')
+ tag = ''
+ date = time.strptime('%sT%s' % (date, ts), '%Y-%m-%dT%H:%M:%SZ')
+ rev += ' (wikipedia.py)'
+ except ValueError:
+ # the value is most likely '$Id' + '$', it means that
+ # wikipedia.py got imported without using svn at all
+ return unknown_version()
+ else:
+ return unknown_version()
datestring = time.strftime('%Y/%m/%d, %H:%M:%S', date)
cache = dict(tag=tag, rev=rev, date=datestring)
return cache
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10916
Revision: 10916
Author: saper
Date: 2013-01-14 10:17:17 +0000 (Mon, 14 Jan 2013)
Log Message:
-----------
Make it possible to [[Special:Export]] full history
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-01-14 10:03:33 UTC (rev 10915)
+++ trunk/pywikipedia/wikipedia.py 2013-01-14 10:17:17 UTC (rev 10916)
@@ -4915,7 +4915,7 @@
if self.site.family.isDefinedNSLanguage(id, lang) and id not in header.namespaces:
output(u"WARNING: Family file %s includes namespace['%s'][%i], but it should be removed (namespace doesn't exist in the site)" % (self.site.family.name, lang, id))
- def getData(self):
+ def getData(self, curonly=True):
address = self.site.export_address()
pagenames = [page.sectionFreeTitle() for page in self.pages]
# We need to use X convention for requested page titles.
@@ -4930,8 +4930,9 @@
predata = {
'action': 'submit',
'pages': pagenames,
- 'curonly': 'True',
}
+ if curonly:
+ predata['curonly'] = 'True'
# Slow ourselves down
get_throttle(requestsize = len(self.pages))
# Now make the actual request to the server
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10913
Revision: 10913
Author: xqt
Date: 2013-01-13 20:07:21 +0000 (Sun, 13 Jan 2013)
Log Message:
-----------
Do not notify uploader if the message is omitted
Modified Paths:
--------------
trunk/pywikipedia/checkimages.py
Modified: trunk/pywikipedia/checkimages.py
===================================================================
--- trunk/pywikipedia/checkimages.py 2013-01-13 20:03:40 UTC (rev 10912)
+++ trunk/pywikipedia/checkimages.py 2013-01-13 20:07:21 UTC (rev 10913)
@@ -146,7 +146,7 @@
msg_comm = {
'ar': u'بوت: التعليم على ملف مرفوع حديثا غير موسوم',
'commons': u'Bot: Marking newly uploaded untagged file',
- 'de': u'Bot: Markierung als Bild ohne Lizenz',
+ 'de': u'Bot: Markiere Bild ohne Lizenz mit {{DÜP}}',
'en': u'Bot: Marking newly uploaded untagged file',
'fa': u'ربات: حق تکثیر تصویر تازه بارگذاری شده نامعلوم است.',
'ga': u'Róbó: Ag márcáil comhad nua-uaslódáilte gan ceadúnas',
@@ -259,18 +259,12 @@
# header that the bot will add if the image hasn't the license.
nothing_head = {
'ar': u"\n== صورة بدون ترخيص ==\n",
- 'commons': u"",# Nothing, the template has already the header inside.
'de': u"\n== Bild ohne Lizenz ==\n",
'en': u"\n== Image without license ==\n",
'ga': u"\n== Comhad gan ceadúnas ==\n",
'fr': u"\n== Fichier sans licence ==\n",
'hu': u"\n== Licenc nélküli kép ==\n",
'it': u"\n\n== File senza licenza ==\n",
- 'ja': u'',
- 'ko': u'',
- 'fa': u'',
- 'ta': u'',
- 'zh': u'',
}
# That's the text that the bot will add if it doesn't find the license.
# Note: every __botnick__ will be repleaced with your bot's nickname (feel free not to use if you don't need it)
@@ -280,7 +274,6 @@
"if you still need help ask at the [[File:Human-help-browser.svg|18px|link=Commons:Help desk|?]] '''[[Commons:Help desk|->]]" + \
"[[Commons:Help desk]]''' in any language you like to use.'' --__botnick__ ~~~~~""",
'ar': u"{{subst:مصدر الصورة|File:%s}} --~~~~",
- 'de': u'\n{{subst:Benutzer:ABF/D2|%s}} ~~~~ ',
'en': u"{{subst:image source|File:%s}} --~~~~",
'fa': u"{{جا:اخطار نگاره|%s}}",
'ga': u"{{subst:Foinse na híomhá|File:%s}} --~~~~",
@@ -524,7 +517,6 @@
"""
-# Other common useful functions
def printWithTimeZone(message):
""" Function to print the messages followed by the TimeZone encoded
correctly.
@@ -943,7 +935,7 @@
def checkImageOnCommons(self):
""" Checking if the file is on commons """
- pywikibot.output(u'Checking if %s is on commons...' % self.imageName)
+ pywikibot.output(u'Checking if [[%s]] is on commons...' % self.imageName)
commons_site = pywikibot.getSite('commons', 'commons')
regexOnCommons = r"\[\[:File:%s\]\] is also on '''Commons''': \[\[commons:File:.*?\]\](?: \(same name\)|)$" \
% re.escape(self.imageName)
@@ -1281,7 +1273,7 @@
fallback=False)
if not catName:
raise pywikibot.Error(u'No licenses allowed provided, add that option to the code to make the script working correctly')
- pywikibot.output(u'\n\t...Loading the licenses allowed...\n')
+ pywikibot.output(u'\nLoading the allowed licenses...\n')
list_licenses = catlib.categoryAllPageObjectsAPI(catName)
if self.site.lang == 'commons':
no_licenses_to_skip = catlib.categoryAllPageObjectsAPI(
@@ -1473,7 +1465,7 @@
rep_text=rep_text_license_fake,
addings=False, regex=regexFakeLicense)
elif self.license_found:
- printWithTimeZone(u"%s seems ok, license found: %s..."
+ printWithTimeZone(u"[[%s]] seems ok, license found: {{%s}}..."
% (self.imageName, self.license_found))
return (self.license_found, self.whiteTemplatesFound)
@@ -1659,6 +1651,7 @@
notallowed = ("xcf", "xls", "sxw", "sxi", "sxc", "sxd")
brackets = False
delete = False
+ notification = None
extension = self.imageName.split('.')[-1] # get the extension from the image's name
# Load the notification messages
HiddenTN = pywikibot.translate(self.site, HiddenTemplateNotification,
@@ -1717,7 +1710,7 @@
#if p.exists(): <-- improve thebot, better to make as
# less call to the server as possible
# Here begins the check block.
- if brackets and not license_found is None:
+ if brackets and license_found:
# It works also without this... but i want only to be sure ^^
brackets = False
return True
@@ -1732,22 +1725,27 @@
delete = False
return True
elif self.imageCheckText in nothing:
- pywikibot.output(u"The file's description for %s does not contain a license template!" % self.imageName)
- if hiddenTemplateFound and HiddenTN != None and HiddenTN != '' and HiddenTN != ' ':
+ pywikibot.output(
+ u"The file's description for %s does not contain a license "
+ u" template!" % self.imageName)
+ if hiddenTemplateFound and HiddenTN:
notification = HiddenTN % self.imageName
- else:
+ elif nn:
notification = nn % self.imageName
head = nh
- self.report(self.unvertext, self.imageName, notification, head, smwl)
+ self.report(self.unvertext, self.imageName, notification, head,
+ smwl)
return True
else:
- pywikibot.output(u"%s has only text and not the specific license..." % self.imageName)
- if hiddenTemplateFound and HiddenTN != None and HiddenTN != '' and HiddenTN != ' ':
+ pywikibot.output(u"%s has only text and not the specific license..."
+ % self.imageName)
+ if hiddenTemplateFound and HiddenTN:
notification = HiddenTN % self.imageName
- else:
+ elif nn:
notification = nn % self.imageName
head = nh
- self.report(self.unvertext, self.imageName, notification, head, smwl)
+ self.report(self.unvertext, self.imageName, notification, head,
+ smwl)
return True