http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9807
Revision: 9807 Author: xqt Date: 2011-12-17 13:55:06 +0000 (Sat, 17 Dec 2011) Log Message: ----------- i18n support; put main stuff into main()
Modified Paths: -------------- trunk/pywikipedia/catall.py
Modified: trunk/pywikipedia/catall.py =================================================================== --- trunk/pywikipedia/catall.py 2011-12-17 13:52:41 UTC (rev 9806) +++ trunk/pywikipedia/catall.py 2011-12-17 13:55:06 UTC (rev 9807) @@ -1,47 +1,25 @@ # -*- coding: utf-8 -*- """ -Add or change categories on a number of pages. Usage: -catall.py name - goes through pages, starting at 'name'. Provides -the categories on the page and asks whether to change them. If no -starting name is provided, the bot starts at 'A'. +Add or change categories on a number of pages. Usage: catall.py name - goes +through pages, starting at 'name'. Provides the categories on the page and asks +whether to change them. If no starting name is provided, the bot starts at 'A'.
Options: -onlynew : Only run on pages that do not yet have a category. """ # # (C) Rob W.W. Hooft, Andre Engels, 2004 -# (C) Pywikipedia bot team, 2004-2010 +# (C) Pywikipedia bot team, 2004-2011 # # Distributed under the terms of the MIT license. # __version__ = '$Id$' #
-import wikipedia as pywikibot import sys +import wikipedia as pywikibot +from pywikibot import i18n
-msg={ - 'ar':u'بوت: تغيير التصنيفات', - 'de':u'Bot: Wechsele Kategorien', - 'en':u'Robot: Changing categories', - 'he':u'Bot: משנה קטגוריות', - 'fa':u'ربات: تغییر ردهها', - 'fr':u'Bot: Change categories', - 'he':u'בוט: משנה קטגוריות', - 'ia':u'Bot: Alteration de categorias', - 'is':u'Vélmenni: Breyti flokkum', - 'it':u'Bot: Cambio categorie', - 'ja':u'ロボットによる: カテゴリ変更', - 'lt':u'robotas: Keičiamos kategorijos', - 'ksh':u'Bot: Saachjruppe tuusche of dobei donn', - 'nl':u'Bot: wijziging van categorieën', - 'pl':u'Bot: Zmiana kategorii', - 'pt':u'Bot: Categorizando', - 'sr':u'Bot: Измена категорија', - 'sv':u'Bot: Ändrar kategori', - 'zh':u'機器人: 更改分類', - } - def choosecats(pagetext): chosen=[] flag=False @@ -85,25 +63,25 @@ cattitle="%s:%s" % (site.category_namespace(), p) pllist.append(pywikibot.Page(site,cattitle)) page.put_async(pywikibot.replaceCategoryLinks(page.get(), pllist), - comment=pywikibot.translate(site.lang, msg)) + comment=i18n.twtranslate(site.lang, 'catall-changing'))
-docorrections=True -start=[] +def main(): + docorrections=True + start=[]
-for arg in pywikibot.handleArgs(): - if arg == '-onlynew': - docorrections=False + for arg in pywikibot.handleArgs(): + if arg == '-onlynew': + docorrections=False + else: + start.append(arg) + + if start == []: + start='A' else: - start.append(arg) + start=' '.join(start)
-if start == []: - start='A' -else: - start=' '.join(start) + mysite = pywikibot.getSite()
-mysite = pywikibot.getSite() - -try: for p in mysite.allpages(start = start): try: text=p.get() @@ -111,22 +89,25 @@ if cats == []: pywikibot.output(u"========== %s ==========" % p.title()) print "No categories" - print "----------------------------------------" + print "-" * 40 newcats=choosecats(text) if newcats != [] and newcats is not None: make_categories(p, newcats, mysite) - else: - if docorrections: - pywikibot.output(u"========== %s ==========" % p.title()) - for c in cats: - pywikibot.output(c.title()) - print "----------------------------------------" - newcats=choosecats(text) - if newcats is None: - make_categories(p, [], mysite) - elif newcats != []: - make_categories(p, newcats, mysite) + elif docorrections: + pywikibot.output(u"========== %s ==========" % p.title()) + for c in cats: + pywikibot.output(c.title()) + print "-" * 40 + newcats=choosecats(text) + if newcats is None: + make_categories(p, [], mysite) + elif newcats != []: + make_categories(p, newcats, mysite) except pywikibot.IsRedirectPage: pywikibot.output(u'%s is a redirect' % p.title()) -finally: - pywikibot.stopme() + +if __name__ == "__main__": + try: + main() + finally: + pywikibot.stopme()
pywikipedia-svn@lists.wikimedia.org