Revision: 7923
Author: xqt
Date: 2010-02-11 15:20:48 +0000 (Thu, 11 Feb 2010)
Log Message:
-----------
iw: remove unused debug-option
Modified Paths:
--------------
trunk/pywikipedia/interwiki.py
Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py 2010-02-10 04:57:20 UTC (rev 7922)
+++ trunk/pywikipedia/interwiki.py 2010-02-11 15:20:48 UTC (rev 7923)
@@ -538,7 +538,6 @@
confirm = False
always = False
select = False
- debug = True
followredirect = True
initialredirect = False
force = False
@@ -1527,7 +1526,7 @@
raise "Bugcheck: finish called before done"
if not self.workonme:
return
- if self.forcedStop:
+ if self.forcedStop: # autonomous with problem
pywikibot.output(u"======Aborted processing %s======" % self.originPage.aslink(True))
return
if self.originPage.isRedirectPage():
@@ -1543,7 +1542,7 @@
pywikibot.output(u"======Post-processing %s======" % self.originPage.aslink(True))
# Assemble list of accepted interwiki links
new = self.assemble()
- if new is None: # User said give up or autonomous with problem
+ if new is None: # User said give up
pywikibot.output(u"======Aborted processing %s======" % self.originPage.aslink(True))
return
@@ -1732,8 +1731,7 @@
return False
if newtext == oldtext:
return False
- if globalvar.debug:
- pywikibot.showDiff(oldtext, newtext)
+ pywikibot.showDiff(oldtext, newtext)
# pywikibot.output(u"NOTE: Replace %s" % page.aslink())
# Determine whether we need permission to submit
Revision: 7919
Author: xqt
Date: 2010-02-08 15:37:02 +0000 (Mon, 08 Feb 2010)
Log Message:
-----------
read magic word aliases for DEFAULTSORT via API (Bugfix for #2827630)
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2010-02-08 11:24:22 UTC (rev 7918)
+++ trunk/pywikipedia/wikipedia.py 2010-02-08 15:37:02 UTC (rev 7919)
@@ -2427,9 +2427,17 @@
if self.site().isInterwikiLink(name):
continue
+ # {{#if: }}
+ if name.startswith('#'):
+ continue
# {{DEFAULTSORT:...}} or {{#if: }}
- if name.startswith('DEFAULTSORT:') or name.startswith('#'):
- continue
+ defaultKeys = self.site().siteinfo('magicwords')['defaultsort']
+ found = False
+ for key in defaultKeys:
+ if name.startswith(key):
+ found = True
+ break
+ if found: continue
try:
name = Page(self.site(), name).title()
@@ -4210,12 +4218,12 @@
self.lock = threading.RLock()
self.mindelay = mindelay
self.maxdelay = maxdelay
+ self.now = 0
self.pid = False # If self.pid remains False, we're not checking for multiple processes
- self.now = 0
self.next_multiplicity = 1.0
self.checkdelay = 240 # Check the file with processes again after this many seconds
self.dropdelay = 360 # Drop processes from the list that have not made a check in this many seconds
- self.releasepid = 100000 # Free the process id
+ self.releasepid = 1200 # Free the process id
self.lastwait = 0.0
self.delay = 0
if multiplydelay:
@@ -6328,8 +6336,13 @@
if not hasattr(self, '_info'):
self._info = data
else:
- for k, v in data.iteritems():
- self._info[k] = v
+ if key == 'magicwords':
+ self._info[key]={}
+ for entry in data[key]:
+ self._info[key][entry['name']] = entry['aliases']
+ else:
+ for k, v in data.iteritems():
+ self._info[k] = v
#data pre-process
try:
if dump:
@@ -6527,10 +6540,16 @@
Use API when enabled use_api and version >= 1.11,
or use Special:Search.
"""
- if config.use_api and self.versionnumber() >= 11:
+ try:
+ if config.use_api and self.versionnumber() >= 11:
+ apiUrl = self.site().api_address()
+ del apiUrl
+ else:
+ raise NotImplementedError
+ except NotImplementedError:
+ _search = self._search_without_api
+ else:
_search = self._search_with_api
- else:
- _search = self._search_without_api
return _search(query, number, namespaces)
def _search_with_api(self, q, number, namespaces):
Revision: 7917
Author: xqt
Date: 2010-02-08 10:53:26 +0000 (Mon, 08 Feb 2010)
Log Message:
-----------
actualized from rewrite, use pagegenerators
Modified Paths:
--------------
trunk/pywikipedia/archive/touch.py
Modified: trunk/pywikipedia/archive/touch.py
===================================================================
--- trunk/pywikipedia/archive/touch.py 2010-02-08 10:11:36 UTC (rev 7916)
+++ trunk/pywikipedia/archive/touch.py 2010-02-08 10:53:26 UTC (rev 7917)
@@ -2,41 +2,36 @@
# -*- coding: utf-8 -*-
"""
-This bot goes over multiple pages of the home wiki, and edits them without
+This bot goes over multiple pages of a wiki, and edits them without
changing. This is for example used to get category links in templates
working.
This script understands various command-line arguments:
- -start: used as -start:page_name, specifies that the robot should
- go alphabetically through all pages on the home wiki,
- starting at the named page.
+¶ms;
- -file: used as -file:file_name, read a list of pages to treat
- from the named textfile. Page titles should be enclosed
- in [[double-squared brackets]].
+-redir specifies that the robot should touch redirect pages;
+ otherwise, they will be skipped.
- -ref: used as -start:page_name, specifies that the robot should
- touch all pages referring to the named page.
-
- -links: used as -links:page_name, specifies that the robot should
- touch all pages referred to from the named page.
-
- -cat: used as -cat:category_name, specifies that the robot should
- touch all pages in the named category.
-
- -redir specifies that the robot should touch redirect pages;
- otherwise, they will be skipped.
-
All other parameters will be regarded as a page title; in this case, the bot
will only touch a single page.
"""
-__version__='$Id: touch.py,v 1.13 2006/03/01 14:07:06 russblau Exp $'
+#
+# (C) Pywikipedia team
+#
+__version__='$Id: touch.py 6549 2009-03-24 02:58:56Z nicdumz $'
+#
+# Distributed under the terms of the MIT license.
+#
-import wikipedia, pagegenerators, catlib, config
+import wikipedia as pywikibot
+import pagegenerators, catlib, config
import sys
+docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
+
+
class TouchBot:
def __init__(self, generator, touch_redirects):
self.generator = generator
@@ -50,12 +45,14 @@
# depends on the variable self.touch_redirects.
text = page.get(get_redirect = self.touch_redirects)
page.put(text)
- except wikipedia.NoPage:
- print "Page %s does not exist?!" % page.aslink()
- except wikipedia.IsRedirectPage:
- print "Page %s is a redirect; skipping." % page.aslink()
- except wikipedia.LockedPage:
- print "Page %s is locked?!" % page.aslink()
+ except pywikibot.NoPage:
+ pywikibot.output(u"Page %s does not exist?!" % page.aslink())
+ except pywikibot.IsRedirectPage:
+ pywikibot.output(u"Page %s is a redirect; skipping." % page.aslink())
+ except pywikibot.LockedPage:
+ pywikibot.output(u"Page %s is locked?!" % page.aslink())
+ except pywikibot.PageNotSaved:
+ pywikibot.output(u"Page %s not saved" % page.aslink())
def main():
# Disable cosmetic changes because we don't want to modify any page
@@ -63,44 +60,36 @@
config.cosmetic_changes = False
#page generator
gen = None
+ genFactory = pagegenerators.GeneratorFactory()
redirs = False
# If the user chooses to work on a single page, this temporary array is
# used to read the words from the page title. The words will later be
# joined with spaces to retrieve the full title.
pageTitle = []
- for arg in wikipedia.handleArgs():
- if arg.startswith('-start:'):
- page = wikipedia.Page(wikipedia.getSite(), arg[7:])
- gen = pagegenerators.AllpagesPageGenerator(page.titleWithoutNamespace(), namespace = page.namespace())
- elif arg.startswith('-ref:'):
- referredPage = wikipedia.Page(wikipedia.getSite(), arg[5:])
- gen = pagegenerators.ReferringPageGenerator(referredPage)
- elif arg.startswith('-links:'):
- linkingPage = wikipedia.Page(wikipedia.getSite(), arg[7:])
- gen = pagegenerators.LinkedPageGenerator(linkingPage)
- elif arg.startswith('-file:'):
- gen = pagegenerators.TextfilePageGenerator(arg[6:])
- elif arg.startswith('-cat:'):
- cat = catlib.Category(wikipedia.getSite(), arg[5:])
- gen = pagegenerators.CategorizedPageGenerator(cat)
- elif arg == '-redir':
+ for arg in pywikibot.handleArgs():
+ if genFactory.handleArg(arg):
+ continue
+ if arg == '-redir':
redirs = True
else:
pageTitle.append(arg)
- if pageTitle:
- # work on a single page
- page = wikipedia.Page(wikipedia.getSite(), ' '.join(pageTitle))
- gen = iter([page])
+ gen = genFactory.getCombinedGenerator()
if not gen:
- wikipedia.showHelp('touch')
- else:
- preloadingGen = pagegenerators.PreloadingGenerator(gen)
- bot = TouchBot(preloadingGen, redirs)
- bot.run()
+ if pageTitle:
+ # work on a single page
+ page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
+ gen = iter([page])
+ else:
+ pywikibot.showHelp('touch')
+ return
+ preloadingGen = pagegenerators.PreloadingGenerator(gen)
+ bot = TouchBot(preloadingGen, redirs)
+ bot.run()
+
if __name__ == "__main__":
try:
main()
finally:
- wikipedia.stopme()
+ pywikibot.stopme()