Revision: 7637 Author: xqt Date: 2009-11-12 14:29:17 +0000 (Thu, 12 Nov 2009)
Log Message: ----------- wikipedia as pywikibot (for easy compare with trunk)
Modified Paths: -------------- trunk/pywikipedia/template.py
Modified: trunk/pywikipedia/template.py =================================================================== --- trunk/pywikipedia/template.py 2009-11-12 14:27:56 UTC (rev 7636) +++ trunk/pywikipedia/template.py 2009-11-12 14:29:17 UTC (rev 7637) @@ -89,7 +89,8 @@ # __version__='$Id$' # -import wikipedia, config +import wikipedia as pywikibot +import config import replace, pagegenerators import re, sys, string, catlib
@@ -115,7 +116,7 @@ Yield page objects until the entire XML dump has been read. """ import xmlreader - mysite = wikipedia.getSite() + mysite = pywikibot.getSite() dump = xmlreader.XmlDump(self.xmlfilename) # regular expression to find the original template. # {{vfd}} does the same thing as {{Vfd}}, so both will be found. @@ -124,7 +125,7 @@ templatePatterns = [] for template in self.templates: templatePattern = template.titleWithoutNamespace() - if not wikipedia.getSite().nocapitalize: + if not pywikibot.getSite().nocapitalize: templatePattern = '[' + templatePattern[0].upper() + templatePattern[0].lower() + ']' + templatePattern[1:] templatePattern = re.sub(' ', '[_ ]', templatePattern) templatePatterns.append(templatePattern) @@ -132,7 +133,7 @@
for entry in dump.parse(): if templateRegex.search(entry.text): - page = wikipedia.Page(mysite, entry.title) + page = pywikibot.Page(mysite, entry.title) yield page
class TemplateRobot: @@ -298,27 +299,27 @@ self.acceptAll = acceptAll self.addedCat = addedCat if self.addedCat: - self.addedCat = catlib.Category(wikipedia.getSite(), 'Category:' + self.addedCat) + self.addedCat = catlib.Category(pywikibot.getSite(), 'Category:' + self.addedCat)
# get edit summary message if it's empty if (self.editSummary==''): oldTemplateNames = (', ').join(self.templates.keys()) - mysite = wikipedia.getSite() + mysite = pywikibot.getSite() if self.remove: if len(self.templates) > 1: - self.editSummary = wikipedia.translate(mysite, self.msgs_remove) % oldTemplateNames + self.editSummary = pywikibot.translate(mysite, self.msgs_remove) % oldTemplateNames else: - self.editSummary = wikipedia.translate(mysite, self.msg_remove) % oldTemplateNames + self.editSummary = pywikibot.translate(mysite, self.msg_remove) % oldTemplateNames elif self.subst: if len(self.templates) > 1: - self.editSummary = wikipedia.translate(mysite, self.msgs_subst) % oldTemplateNames + self.editSummary = pywikibot.translate(mysite, self.msgs_subst) % oldTemplateNames else: - self.editSummary = wikipedia.translate(mysite, self.msg_subst) % oldTemplateNames + self.editSummary = pywikibot.translate(mysite, self.msg_subst) % oldTemplateNames else: if len(self.templates) > 1: - self.editSummary = wikipedia.translate(mysite, self.msgs_change) % oldTemplateNames + self.editSummary = pywikibot.translate(mysite, self.msgs_change) % oldTemplateNames else: - self.editSummary = wikipedia.translate(mysite, self.msg_change) % oldTemplateNames + self.editSummary = pywikibot.translate(mysite, self.msg_change) % oldTemplateNames
def run(self): """ @@ -333,7 +334,7 @@ replacements = []
for old, new in self.templates.iteritems(): - if not wikipedia.getSite().nocapitalize: + if not pywikibot.getSite().nocapitalize: pattern = '[' + re.escape(old[0].upper()) + re.escape(old[0].lower()) + ']' + re.escape(old[1:]) else: pattern = re.escape(old) @@ -363,14 +364,14 @@ # If xmlfilename is None, references will be loaded from the live wiki. xmlfilename = None # read command line parameters - for arg in wikipedia.handleArgs(): + for arg in pywikibot.handleArgs(): if arg == '-remove': remove = True elif arg == '-subst': subst = True elif arg.startswith('-xml'): if len(arg) == 4: - xmlfilename = wikipedia.input(u'Please enter the XML dump's filename: ') + xmlfilename = pywikibot.input(u'Please enter the XML dump's filename: ') else: xmlfilename = arg[5:] elif arg.startswith('-namespace:'): @@ -396,13 +397,13 @@ for i in range(0, len(templateNames), 2): templates[templateNames[i]] = templateNames[i + 1] except IndexError: - wikipedia.output(u'Unless using -subst or -remove, you must give an even number of template names.') + pywikibot.output(u'Unless using -subst or -remove, you must give an even number of template names.') return
oldTemplates = [] - ns = wikipedia.getSite().template_namespace() + ns = pywikibot.getSite().template_namespace() for templateName in templates.keys(): - oldTemplate = wikipedia.Page(wikipedia.getSite(), ns + ':' + templateName) + oldTemplate = pywikibot.Page(pywikibot.getSite(), ns + ':' + templateName) oldTemplates.append(oldTemplate)
if xmlfilename: @@ -427,4 +428,4 @@ try: main() finally: - wikipedia.stopme() + pywikibot.stopme()