Revision: 8248
Author: xqt
Date: 2010-06-04 10:59:35 +0000 (Fri, 04 Jun 2010)
Log Message:
-----------
update r8240 from trunk
Modified Paths:
--------------
branches/rewrite/scripts/basic.py
Modified: branches/rewrite/scripts/basic.py
===================================================================
--- branches/rewrite/scripts/basic.py 2010-06-04 10:52:37 UTC (rev 8247)
+++ branches/rewrite/scripts/basic.py 2010-06-04 10:59:35 UTC (rev 8248)
@@ -15,7 +15,14 @@
All other parameters will be regarded as part of the title of a single page,
and the bot will only work on that single page.
"""
+#
+# (C) Pywikipedia bot team, 2006-2010
+#
+# Distributed under the terms of the MIT license.
+#
__version__ = '$Id$'
+#
+
import pywikibot
from pywikibot import pagegenerators
@@ -71,10 +78,12 @@
# Load the page
text = page.get()
except pywikibot.NoPage:
- pywikibot.output(u"Page %s does not exist; skipping." % page.title(asLink=True))
+ pywikibot.output(u"Page %s does not exist; skipping."
+ % page.title(asLink=True))
return
except pywikibot.IsRedirectPage:
- pywikibot.output(u"Page %s is a redirect; skipping." % page.title(asLink=True))
+ pywikibot.output(u"Page %s is a redirect; skipping."
+ % page.title(asLink=True))
return
################################################################
@@ -89,7 +98,8 @@
if text != page.get():
# Show the title of the page we're working on.
# Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
+ pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
+ % page.title())
# show what was changed
pywikibot.showDiff(page.get(), text)
if not self.dry:
Revision: 8247
Author: xqt
Date: 2010-06-04 10:52:37 +0000 (Fri, 04 Jun 2010)
Log Message:
-----------
comment translations for changing commonscat template content
Modified Paths:
--------------
trunk/pywikipedia/commonscat.py
Modified: trunk/pywikipedia/commonscat.py
===================================================================
--- trunk/pywikipedia/commonscat.py 2010-06-04 10:16:15 UTC (rev 8246)
+++ trunk/pywikipedia/commonscat.py 2010-06-04 10:52:37 UTC (rev 8247)
@@ -15,9 +15,8 @@
-always Don't prompt you for each replacement. Warning message
has not to be confirmed. ATTENTION: Use this with care!
--summary:XYZ Set the action summary message for the edit to XYZ.
- There is no predefined message text yet and this option is
- recommended.
+-summary:XYZ Set the action summary message for the edit to XYZ,
+ otherwise it uses messages from add_text.py as default.
-checkcurrent Work on all category pages that use the primary commonscat
template.
@@ -151,6 +150,13 @@
'ru' : [u'Навигация'],
}
+msg_change = {
+ 'de': u'Bot: Ändere commonscat link von [[:Commons:Category: %(oldcat)s|%(oldcat)s zu [[:Commons:Category:%(newcat)s|%(newcat)s]]',
+ 'en': u'Robot: Changing commonscat link from [[:Commons:Category: %(oldcat)s|%(oldcat)s to [[:Commons:Category:%(newcat)s|%(newcat)s]]',
+ 'fr': u'Robot: Changé commonscat link de [[:Commons:Category: %(oldcat)s|%(oldcat)s à [[:Commons:Category:%(newcat)s|%(newcat)s]]',
+ 'pdc': u'Waddefresser: commonscat Gleecher vun [[:Commons:Category: %(oldcat)s|%(oldcat)s nooch [[:Commons:Category:%(newcat)s|%(newcat)s]] geennert',
+}
+
def getCommonscatTemplate (lang = None):
'''
Get the template name in a language. Expects the language code.
@@ -269,7 +275,7 @@
newtext = re.sub(u'(?i)\{\{' + oldtemplate + u'\|?[^}]*\}\}',
u'{{' + newtemplate + u'|' + newcat + u'}}',
page.get())
- comment = u'Changing commonscat link from [[:Commons:Category:' + oldcat + u'|' + oldcat + u']] to [[:Commons:Category:' + newcat + u'|' + newcat + u']]'
+ comment = pywikibot.translate(page.site(), msg_change) % {'oldcat':oldcat, 'newcat':newcat}
pywikibot.showDiff(page.get(), newtext)
page.put(newtext, comment)
Revision: 8242
Author: xqt
Date: 2010-06-04 07:39:22 +0000 (Fri, 04 Jun 2010)
Log Message:
-----------
separate exception 403 (local virewall or other blocking mechanism)
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2010-06-04 07:03:17 UTC (rev 8241)
+++ trunk/pywikipedia/wikipedia.py 2010-06-04 07:39:22 UTC (rev 8242)
@@ -324,42 +324,42 @@
break
p = m.group(1)
lowerNs = p.lower()
- ns = self.site().getNamespaceIndex(lowerNs)
+ ns = self._site.getNamespaceIndex(lowerNs)
if ns:
t = m.group(2)
self._namespace = ns
break
- if lowerNs in self.site().family.langs.keys():
+ if lowerNs in self._site.family.langs.keys():
# Interwiki link
t = m.group(2)
# Redundant interwiki prefix to the local wiki
- if lowerNs == self.site().lang:
+ if lowerNs == self._site.lang:
if t == '':
raise Error("Can't have an empty self-link")
else:
- self._site = getSite(lowerNs, self.site().family.name)
+ self._site = getSite(lowerNs, self._site.family.name)
# If there's an initial colon after the interwiki, that also
# resets the default namespace
if t != '' and t[0] == ':':
self._namespace = 0
t = t[1:]
- elif lowerNs in self.site().family.get_known_families(site = self.site()):
- if self.site().family.get_known_families(site = self.site())[lowerNs] == self.site().family.name:
+ elif lowerNs in self._site.family.get_known_families(site = self._site):
+ if self._site.family.get_known_families(site = self._site)[lowerNs] == self._site.family.name:
t = m.group(2)
else:
# This page is from a different family
if verbose:
output(u"Target link '%s' has different family '%s'" % (title, lowerNs))
- if self.site().family.name in ['commons', 'meta']:
+ if self._site.family.name in ['commons', 'meta']:
#When the source wiki is commons or meta,
#w:page redirects you to w:en:page
otherlang = 'en'
else:
- otherlang = self.site().lang
- familyName = self.site().family.get_known_families(site = self.site())[lowerNs]
+ otherlang = self._site.lang
+ familyName = self._site.family.get_known_families(site = self._site)[lowerNs]
if familyName in ['commons', 'meta']:
otherlang = familyName
try:
@@ -368,7 +368,7 @@
raise NoPage("""\
%s is not a local page on %s, and the %s family is
not supported by PyWikipediaBot!"""
- % (title, self.site(), familyName))
+ % (title, self._site, familyName))
t = m.group(2)
else:
# If there's no recognized interwiki or namespace,
@@ -383,7 +383,7 @@
if sectionStart > 0 and self._namespace not in [14]:
self._section = t[sectionStart+1 : ].lstrip(" ")
self._section = sectionencode(self._section,
- self.site().encoding())
+ self._site.encoding())
if not self._section:
self._section = None
t = t[ : sectionStart].rstrip(" ")
@@ -393,12 +393,12 @@
self._section = None
if t:
- if not self.site().nocapitalize:
+ if not self._site.nocapitalize:
t = t[:1].upper() + t[1:]
# reassemble the title from its parts
if self._namespace != 0:
- t = self.site().namespace(self._namespace) + u':' + t
+ t = self._site.namespace(self._namespace) + u':' + t
if self._section:
t += u'#' + self._section
@@ -5141,14 +5141,22 @@
raise
except urllib2.HTTPError, e:
if e.code in [401, 404]:
- raise PageNotFound(u'Page %s could not be retrieved. Check your family file ?' % url)
+ raise PageNotFound(
+u'Page %s could not be retrieved. Check your family file.'
+ % url)
+ elif e.code in [403]:
+ raise PageNotFound(
+u'Page %s could not be retrieved. Check your virus wall.'
+ % url)
elif e.code == 504:
output(u'HTTPError: %s %s' % (e.code, e.msg))
if retry:
- output(u"""WARNING: Could not open '%s'.Maybe the server or\n your connection is down. Retrying in %i minutes..."""
+ output(
+u"""WARNING: Could not open '%s'.Maybe the server or\n your connection is down. Retrying in %i minutes..."""
% (url, retry_idle_time))
time.sleep(retry_idle_time * 60)
- # Next time wait longer, but not longer than half an hour
+ # Next time wait longer,
+ # but not longer than half an hour
retry_idle_time *= 2
if retry_idle_time > 30:
retry_idle_time = 30
@@ -5160,7 +5168,8 @@
except Exception, e:
output(u'%s' %e)
if retry:
- output(u"""WARNING: Could not open '%s'. Maybe the server or\n your connection is down. Retrying in %i minutes..."""
+ output(
+u"""WARNING: Could not open '%s'. Maybe the server or\n your connection is down. Retrying in %i minutes..."""
% (url, retry_idle_time))
time.sleep(retry_idle_time * 60)
retry_idle_time *= 2