jenkins-bot has submitted this change and it was merged.
Change subject: [PEP8]ify catall.py ......................................................................
[PEP8]ify catall.py
Change-Id: Ib7184e626d6b973dd577fc1152003d1f07c919dc --- M catall.py 1 file changed, 43 insertions(+), 40 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/catall.py b/catall.py index 41141bf..d2dd254 100644 --- a/catall.py +++ b/catall.py @@ -9,7 +9,7 @@ """ # # (C) Rob W.W. Hooft, Andre Engels, 2004 -# (C) Pywikipedia bot team, 2004-2011 +# (C) Pywikibot team, 2004-2013 # # Distributed under the terms of the MIT license. # @@ -20,77 +20,80 @@ import wikipedia as pywikibot from pywikibot import i18n
+ def choosecats(pagetext): - chosen=[] - flag=False - length=1000 - print ("Give the new categories, one per line.") - print ("Empty line: if the first, don't change. Otherwise: Ready.") - print ("-: I made a mistake, let me start over.") - print ("?: Give the text of the page with GUI.") - print ("??: Give the text of the page in console.") - print ("xx: if the first, remove all categories and add no new.") - print ("q: quit.") - while flag == False: - choice=pywikibot.input(u"?") - if choice=="": - flag=True - elif choice=="-": - chosen=choosecats(pagetext) - flag=True - elif choice=="?": + chosen = [] + done = False + length = 1000 + print("""Give the new categories, one per line. +Empty line: if the first, don't change. Otherwise: Ready. +-: I made a mistake, let me start over. +?: Give the text of the page with GUI. +??: Give the text of the page in console. +xx: if the first, remove all categories and add no new. +q: quit.""") + while not done: + choice = pywikibot.input(u"?") + if choice == "": + done = True + elif choice == "-": + chosen = choosecats(pagetext) + done = True + elif choice == "?": import editarticle editor = editarticle.TextEditor() newtext = editor.edit(pagetext) - elif choice =="??": + elif choice == "??": pywikibot.output(pagetext[0:length]) - length = length+500 - elif choice=="xx" and chosen==[]: + length = length + 500 + elif choice == "xx" and chosen == []: chosen = None - flag=True - elif choice=="q": + done = True + elif choice == "q": print "quit..." sys.exit() else: chosen.append(choice) return chosen
-def make_categories(page, list, site = None): + +def make_categories(page, list, site=None): if site is None: site = pywikibot.getSite() - pllist=[] + pllist = [] for p in list: - cattitle="%s:%s" % (site.category_namespace(), p) - pllist.append(pywikibot.Page(site,cattitle)) + cattitle = "%s:%s" % (site.category_namespace(), p) + pllist.append(pywikibot.Page(site, cattitle)) page.put_async(pywikibot.replaceCategoryLinks(page.get(), pllist), comment=i18n.twtranslate(site.lang, 'catall-changing'))
+ def main(): - docorrections=True - start=[] + docorrections = True + start = []
for arg in pywikibot.handleArgs(): if arg == '-onlynew': - docorrections=False + docorrections = False else: start.append(arg)
- if start == []: - start='A' + if not start: + start = 'A' else: - start=' '.join(start) + start = ' '.join(start)
mysite = pywikibot.getSite()
- for p in mysite.allpages(start = start): + for p in mysite.allpages(start=start): try: - text=p.get() - cats=p.categories() - if cats == []: + text = p.get() + cats = p.categories() + if not cats: pywikibot.output(u"========== %s ==========" % p.title()) print "No categories" print "-" * 40 - newcats=choosecats(text) + newcats = choosecats(text) if newcats != [] and newcats is not None: make_categories(p, newcats, mysite) elif docorrections: @@ -98,7 +101,7 @@ for c in cats: pywikibot.output(c.title()) print "-" * 40 - newcats=choosecats(text) + newcats = choosecats(text) if newcats is None: make_categories(p, [], mysite) elif newcats != []:
pywikibot-commits@lists.wikimedia.org