Revision: 6197 Author: russblau Date: 2008-12-24 16:05:47 +0000 (Wed, 24 Dec 2008)
Log Message: ----------- convert editarticles.py
Modified Paths: -------------- branches/rewrite/pywikibot/scripts/editarticle.py branches/rewrite/pywikibot/scripts/replace.py
Modified: branches/rewrite/pywikibot/scripts/editarticle.py =================================================================== --- branches/rewrite/pywikibot/scripts/editarticle.py 2008-12-23 21:15:36 UTC (rev 6196) +++ branches/rewrite/pywikibot/scripts/editarticle.py 2008-12-24 16:05:47 UTC (rev 6197) @@ -22,8 +22,8 @@ import optparse import tempfile
-import wikipedia -import config +import pywikibot +from pywikibot import config
msg = { 'ar': u'تعديل يدوي: %s', @@ -118,26 +118,29 @@ os.unlink(tempFilename) return self.restoreLinebreaks(newcontent) else: - return self.restoreLinebreaks(wikipedia.ui.editText(text, jumpIndex = jumpIndex, highlight = highlight)) + return self.restoreLinebreaks(pywikibot.ui.editText(text, jumpIndex = jumpIndex, highlight = highlight))
class ArticleEditor: joinchars = string.letters + '[]' + string.digits # join lines if line starts with this ones
- def __init__(self): - self.set_options() + def __init__(self, *args): + self.set_options(*args) self.setpage() - self.site = wikipedia.getSite() + self.site = pywikibot.getSite()
- def set_options(self): + def set_options(self, *args): """Parse commandline and set options attribute""" my_args = [] - for arg in wikipedia.handleArgs(): + for arg in pywikibot.handleArgs(*args): my_args.append(arg) parser = optparse.OptionParser() - parser.add_option("-r", "--edit_redirect", action="store_true", default=False, help="Ignore/edit redirects") + parser.add_option("-r", "--edit_redirect", action="store_true", + default=False, help="Ignore/edit redirects") parser.add_option("-p", "--page", help="Page to edit") - parser.add_option("-w", "--watch", action="store_true", default=False, help="Watch article after edit") - #parser.add_option("-n", "--new_data", default="", help="Automatically generated content") + parser.add_option("-w", "--watch", action="store_true", default=False, + help="Watch article after edit") + #parser.add_option("-n", "--new_data", default="", + # help="Automatically generated content") (self.options, args) = parser.parse_args(args=my_args)
# for convenience, if we have an arg, stuff it into the opt, so we @@ -147,9 +150,9 @@
def setpage(self): """Sets page and page title""" - site = wikipedia.getSite() - pageTitle = self.options.page or wikipedia.input(u"Page to edit:") - self.page = wikipedia.Page(site, pageTitle) + site = pywikibot.getSite() + pageTitle = self.options.page or pywikibot.input(u"Page to edit:") + self.page = pywikibot.Page(site, pageTitle) if not self.options.edit_redirect and self.page.isRedirectPage(): self.page = self.page.getRedirectTarget()
@@ -158,33 +161,33 @@ fp = open(fn, 'w') fp.write(new) fp.close() - wikipedia.output(u"An edit conflict has arisen. Your edit has been saved to %s. Please try again." % fn) + pywikibot.output(u"An edit conflict has arisen. Your edit has been saved to %s. Please try again." % fn)
def run(self): try: old = self.page.get(get_redirect = self.options.edit_redirect) - except wikipedia.NoPage: + except pywikibot.NoPage: old = "" textEditor = TextEditor() new = textEditor.edit(old) if new and old != new: - wikipedia.showDiff(old, new) - changes = wikipedia.input(u"What did you change?") - comment = wikipedia.translate(wikipedia.getSite(), msg) % changes + pywikibot.showDiff(old, new) + changes = pywikibot.input(u"What did you change?") + comment = pywikibot.translate(pywikibot.getSite(), msg) % changes try: self.page.put(new, comment = comment, minorEdit = False, watchArticle=self.options.watch) - except wikipedia.EditConflict: + except pywikibot.EditConflict: self.handle_edit_conflict(new) else: - wikipedia.output(u"Nothing changed") + pywikibot.output(u"Nothing changed")
-def main(): - app = ArticleEditor() +def main(*args): + app = ArticleEditor(*args) app.run()
if __name__ == "__main__": try: - main() + main(*args) finally: - wikipedia.stopme() + pywikibot.stopme()
Modified: branches/rewrite/pywikibot/scripts/replace.py =================================================================== --- branches/rewrite/pywikibot/scripts/replace.py 2008-12-23 21:15:36 UTC (rev 6196) +++ branches/rewrite/pywikibot/scripts/replace.py 2008-12-24 16:05:47 UTC (rev 6197) @@ -117,7 +117,7 @@ import sys, re, time import pywikibot from pywikibot import pagegenerators, catlib, config -# import editarticle +from pywikibot.scripts import editarticle import webbrowser
# Imports predefined replacements tasks from fixes.py