http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11155
Revision: 11155
Author: xqt
Date: 2013-03-02 10:39:02 +0000 (Sat, 02 Mar 2013)
Log Message:
-----------
some PEP8 changes
Modified Paths:
--------------
trunk/pywikipedia/basic.py
Modified: trunk/pywikipedia/basic.py
===================================================================
--- trunk/pywikipedia/basic.py 2013-03-02 10:37:00 UTC (rev 11154)
+++ trunk/pywikipedia/basic.py 2013-03-02 10:39:02 UTC (rev 11155)
@@ -36,6 +36,7 @@
'¶ms;': pagegenerators.parameterHelp
}
+
class BasicBot:
# Edit summary message that should be used is placed on /i18n subdirectory.
# The file containing these messages should have the same name as the
caller
@@ -108,7 +109,7 @@
% page.title())
# show what was changed
pywikibot.showDiff(page.get(), text)
- pywikibot.output(u'Comment: %s' %comment)
+ pywikibot.output(u'Comment: %s' % comment)
choice = pywikibot.inputChoice(
u'Do you want to accept these changes?',
['Yes', 'No'], ['y', 'N'], 'N')
@@ -131,6 +132,7 @@
return True
return False
+
class AutoBasicBot(BasicBot):
# Intended for usage e.g. as cronjob without prompting the user.
@@ -142,23 +144,31 @@
## @since 10326
# @remarks needed by various bots
def save(self, page, text, comment=None, **kwargs):
- pywikibot.output(u'\03{lightblue}Writing to wiki on %s...\03{default}'
% page.title(asLink=True))
+ pywikibot.output(u'\03{lightblue}Writing to wiki on %s...\03{default}'
+ % page.title(asLink=True))
comment_output = comment or pywikibot.action
- pywikibot.output(u'\03{lightblue}Comment: %s\03{default}' %
comment_output)
+ pywikibot.output(u'\03{lightblue}Comment: %s\03{default}'
+ % comment_output)
#pywikibot.showDiff(page.get(), text)
- for i in range(3): # try max. 3 times
+ for i in range(3):
try:
# Save the page
page.put(text, comment=comment, **kwargs)
except pywikibot.LockedPage:
- pywikibot.output(u"\03{lightblue}Page %s is locked;
skipping.\03{default}" % page.title(asLink=True))
+ pywikibot.output(
+ u"\03{lightblue}Page %s is locked; skipping.\03{default}"
+ % page.title(asLink=True))
except pywikibot.EditConflict:
- pywikibot.output(u'\03{lightblue}Skipping %s because of edit
conflict\03{default}' % (page.title()))
+ pywikibot.output(
+ u'\03{lightblue}Skipping %s because of edit '
+ u'conflict\03{default}' % (page.title()))
except pywikibot.SpamfilterError, error:
- pywikibot.output(u'\03{lightblue}Cannot change %s because of
spam blacklist entry %s\03{default}' % (page.title(), error.url))
+ pywikibot.output(
+ u'\03{lightblue}Cannot change %s because of spam blacklist
'
+ u'entry %s\03{default}' % (page.title(), error.url))
else:
return True
return False
@@ -167,18 +177,22 @@
# @remarks needed by various bots
def append(self, page, text, comment=None, section=None, **kwargs):
if section:
- pywikibot.output(u'\03{lightblue}Appending to wiki on %s in
section %s...\03{default}' % (page.title(asLink=True), section))
-
- for i in range(3): # try max. 3 times
+ pywikibot.output(
+ u'\03{lightblue}Appending to wiki on %s in section '
+ u'%s...\03{default}' % (page.title(asLink=True), section))
+ for i in range(3):
try:
# Append to page section
- page.append(text, comment=comment, section=section,
**kwargs)
+ page.append(text, comment=comment, section=section,
+ **kwargs)
except pywikibot.PageNotSaved, error:
- pywikibot.output(u'\03{lightblue}Cannot change %s because
of %s\03{default}' % (page.title(), error))
+ pywikibot.output(
+ u'\03{lightblue}Cannot change %s because of '
+ u'%s\03{default}' % (page.title(), error))
else:
return True
else:
- content = self.load( page ) # 'None' if not existing page
+ content = self.load(page) # 'None' if not existing page
if not content: # (create new page)
content = u''
@@ -197,7 +211,7 @@
Returns a list of dict with the templates parameters found.
"""
- self._content = self.load(page) # 'None' if not existing page
+ self._content = self.load(page) # 'None' if not existing page
templates = []
if not self._content:
@@ -208,7 +222,7 @@
param_default = {}
param_default.update(default)
param_default.update(tmpl[1])
- templates.append( param_default )
+ templates.append(param_default)
return templates
## @since 10326
@@ -226,8 +240,10 @@
Returns a list of jobs. This list may be empty.
"""
- try: actual = page.getVersionHistory(revCount=1)[0]
- except: pass
+ try:
+ actual = page.getVersionHistory(revCount=1)[0]
+ except:
+ pass
secure = False
for item in queue_security[0]:
@@ -235,20 +251,21 @@
secure = secure and (actual[3] == queue_security[1])
- if not secure: return []
+ if not secure:
+ return []
data = self._REGEX_eol.split(page.get())
if reset:
pywikibot.output(u'\03{lightblue}Job queue reset...\03{default}')
-
pywikibot.setAction(u'reset job queue')
- page.put(u'', minorEdit = True)
+ page.put(u'', minorEdit=True)
queue = []
for line in data:
- queue.append( line[1:].strip() )
+ queue.append(line[1:].strip())
return queue
+
def main():
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn