#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This script understands various command-line arguments:
-interactive: ask before changing each page
-nocache doesn't include /cache/featured /cache/lists or /cache/good
file to remember if the article already was verified.
-fromlang:xx,yy xx,yy,zz,.. are the languages to be verified.
-fromlang:ar--fi Another possible with range the languages
-fromall to verify all languages.
-after:zzzz process pages after and including page zzzz
-top use -top if you want to move all {{Link FA|lang}} to the top
of the interwiki links. Default is placing {{Link FA|lang}}
next to the corresponding interwiki link.
-count Only counts how many featured/good articles exist
on all wikis (given with the "-fromlang" argument) or
on several language(s) (when using the "-fromall" argument).
Example: featured.py -fromlang:en,he -count
counts how many featured articles exist in the en and he
wikipedias.
-lists use this script for featured lists.
-good use this script for good articles.
-former use this script for removing {{Link FA|xx}} from former fearured articles
-quiet no corresponding pages are displayed.
-dry for debug purposes. No changes will be made.
usage: featured.py [-interactive] [-nocache] [-top] [-after:zzzz] [-fromlang:xx,yy--zz|-fromall]
"""
__version__ = '$Id: featured.py 8224 2010-05-27 10:42:12Z xqt $'
#
# (C) Maxim Razin, 2005
# (C) Leonardo Gregianin, 2005-2008
# (C) xqt, 2009-2010
# (C) Pywikipedia bot team, 2005-2010
#
# Distributed under the terms of the MIT license.
#
import sys, re, pickle, os.path
import wikipedia, catlib, config
def CAT(site,name):
name = site.namespace(14) + ':' + name
cat=catlib.Category(site, name)
return cat.articles()
def BACK(site,name):
name = site.namespace(10) + ':' + name
p=wikipedia.Page(site, name)
return [page for page in p.getReferences(follow_redirects = False, onlyTemplateInclusion=True)]
msg = {
'als':u'Btli: [[%s:%s]] isch en bsunders glungener Artikel',
'ar': u': [[%s:%s]] ',
'bat-smg': u'robots: Pavzdn straipsn nruoda [[%s:%s]]',
'be-x-old': u': [[%s:%s]] ',
'bs': u'Bot: Interwiki za izabrane lanke za [[%s:%s]]',
'cs': u'Robot pidal nejlep lnek: [[%s:%s]]',
'cy': u'Robot: Mae [[%s:%s]] yn erthygl ddethol',
'de': u'Bot: [[%s:%s]] ist ein ausgezeichneter Artikel',
'dsb':u'Bot: [[%s:%s]] jo wubrny nastawk',
'en': u'Bot: [[%s:%s]] is a featured article',
'eo': u'roboto: [[%s:%s]] estas artikolo elstara',
'es': u'Bot: Enlace a artculo destacado para: [[%s:%s]]',
'fa': u' : [[%s:%s]] ',
'fi': u'Botti: [[%s:%s]] on suositeltu artikkeli',
'fr': u'Bot: Lien AdQ pour [[%s:%s]]',
'he': u': [[%s:%s]]',
'hr': u'Bot: Interwiki za izabrane lanke za [[%s:%s]]',
'hsb':u'Bot: [[%s:%s]] je wubrny nastawk',
'hu': u'Bot: a(z) [[%s:%s]] kiemelt szcikk',
'ia': u'Robot: Ligamine verso articulo eminente [[%s:%s]]',
'it': u'Bot: collegamento articolo in vetrina [[%s:%s]]',
'ja': u': [[%s:%s]]',
'ka': u': [[%s:%s]]',
'ko': u': [[%s:%s]] ',#?
'ksh':u'bot: [[%s:%s]] ess_enen ujezijshneten Atikkel',
'lb': u'Bot: Exzellenten Arikel Link op [[%s:%s]]',
'lt': u'Bot: Pavyzdinis straipsnis [[%s:%s]]',
'nl': u'Bot: verwijzing naar etalage-artikel voor [[%s:%s]]',
'no': u'bot: [[%s:%s]] er en utmerka artikkel',
'nn': u'bot: [[%s:%s]] er ein god artikkel',
'nv': u'Naaltsoos [[%s:%s]] kad nizhngo lyaa',
'mk': u': [[%s:%s]]',
'pl': u'Bot: Link do artykuu wyrnionego [[%s:%s]]',
'pt': u'Bot: Ligando artigos destacados para [[%s:%s]]',
'ru': u': [[%s:%s]]',
'sk': u'Bot: [[%s:%s]] je najlep lnok',
'sr': u'Bot: [[%s:%s]]',
'sv': u'Bot: [[%s:%s]] r en utmrkt artikel',
'th': u': [[%s:%s]]',
'tr': u'Bot deiiklii: [[%s:%s]] madde balants eklendi',
'vo': u'Bot: Ym yegeda gudik tef [[%s:%s]]',
'zh': u': [[%s:%s]]',
}
msg_good = {
'als': u'Btli: [[%s:%s]] isch en glungener Artikel',
'ar': u': [[%s:%s]] ',
'cy': u'Robot: Mae [[%s:%s]] yn erthygl dda',
'de': u'Bot: [[%s:%s]] ist ein lesenswerter Artikel',
'en': u'Bot: [[%s:%s]] is a good article',
'eo': u'roboto: [[%s:%s]] estas artikolo leginda',
'es': u'Bot: Enlace a artculo bueno para: [[%s:%s]]',
'fa': u': [[%s:%s]] ',
'fi': u'Botti: [[%s:%s]] on hyv artikkeli',
'fr': u'Bot: Lien BA pour [[%s:%s]]',
'ksh':u'bot: [[%s:%s]] ess_enen jooden Atikkel',
'no': u'bot: [[%s:%s]] er en anbefalt artikkel',
'nn': u'bot: [[%s:%s]] er ein god artikkel',
'pl': u'Bot: Link do dobrego artykuu: [[%s:%s]]',
'ru': u': [[%s:%s]]',
'sv': u'Bot: [[%s:%s]] r en lsvrd artikel',
}
msg_lists = {
'als':u'Btli: [[%s:%s]] isch e bsunders glungene Lischte',
'ar': u': [[%s:%s]] ',
'de': u'Bot: [[%s:%s]] ist eine informative Liste',
'en': u'Bot: [[%s:%s]] is a featured list',
'es': u'Bot: Enlace a lista destacado para: [[%s:%s]]',
'fa': u':[[%s:%s]] ',
'fi': u'Botti: [[%s:%s]] on suositeltu luettelo',
'ksh':u'bot: [[%s:%s]] ess_en joode Le',
'sv': u'Bot: [[%s:%s]] r en utmrkt list',
}
msg_former = {
'en': u'Bot: [[%s:%s]] is a former featured article',
'fa': u': [[%s:%s]] .',
}
# ALL wikis use 'Link FA', and sometimes other localized templates.
# We use _default AND the localized ones
template = {
'_default': ['Link FA'],
'als': ['LinkFA'],
'an': ['Destacato', 'Destacau'],
'ar': [u' '],
'ast':['Enllaz AD'],
'az': ['Link FM'],
'br': ['Liamm PuB', 'Lien AdQ'],
'ca': [u'Enlla AD', 'Destacat'],
'cy': ['Cyswllt erthygl ddethol', 'Dolen ED'],
'eo': ['LigoElstara'],
'en': ['Link FA', 'FA link'],
'es': ['Destacado'],
'eu': ['NA lotura'],
'fr': ['Lien AdQ'],
'fur':['Leam VdC'],
'ga': ['Nasc AR'],
'hi': ['Link FA', 'Lien AdQ'],
'is': [u'Tengill G'],
'it': ['Link AdQ'],
'no': ['Link UA'],
'oc': ['Ligam AdQ', 'Lien AdQ'],
'ro': [u'Legtur AC', u'Legtur AF'],
'sv': ['UA', 'Link UA'],
'tr': ['Link SM'],
'vi': [u'Lin kt chn lc'],
'vo': [u'Ym YG'],
'yi': [u''],
}
template_good = {
'_default': ['Link GA'],
'ar': [u' '],
'da': ['Link GA', 'Link AA'],
'eo': ['LigoLeginda'],
'es': ['Bueno'],
'fr': ['Lien BA'],
'is': ['Tengill GG'],
'nn': ['Link AA'],
'no': ['Link AA'],
#'tr': ['Link GA', 'Link KM'],
'vi': [u'Lin kt bi cht lng tt'],
'wo': ['Lien BA'],
}
template_lists = {
'_default': ['Link FL'],
}
featured_name = {
'af': (BACK,u"Voorbladster"),
'als':(CAT, u"Wikipedia:Bsunders glungener Artikel"),
'am': (CAT, u"Wikipedia:Featured article"),
'an': (CAT, u"Articlos destacatos"),
'ar': (CAT, u" "),
'ast':(CAT, u"Uiquipedia:Artculos destacaos"),
'az': (BACK,u"Seilmi mqal"),
'bar':(CAT, u"Berig"),
'bat-smg': (CAT, u"Vikipedjs pavzdn straipsn"),
'be-x-old':(CAT, u": "),
'bg': (CAT, u" "),
'bn': (BACK,u" "),
'br': (CAT, u"Pennado eus an dibab"),
'bs': (CAT, u"Odabrani lanci"),
'ca': (CAT, u"Llista d'articles de qualitat"),
'ceb':(CAT, u"Mga napiling artikulo"),
'cs': (CAT, u"Nejlep lnky"),
'cy': (CAT, u"Erthyglau dethol"),
'da': (CAT, u"Fremragende artikler"),
'de': (CAT, u"Wikipedia:Exzellent"),
#'dsb':(CAT, u"Ekscelentny"),
'dv': (BACK, u"Featured article"),
#'dv': (CAT, u"Featured Articles"),
'el': (BACK,u" "),
'eo': (CAT, u"Elstaraj artikoloj"),
'en': (CAT, u"Featured articles"),
'es': (BACK, u"Artculo destacado"),
'et': (CAT, u"Eeskujulikud artiklid"),
'eu': (CAT, u"Nabarmendutako artikuluak"),
'ext':(BACK,u"Destacau"),
'fa': (BACK,u" "),
'fi': (CAT, u"Suositellut sivut"),
'fo': (CAT, u"Mnaargrein"),
'fr': (CAT, u"Article de qualit"),
'gv': (CAT, u"Artyn reiht"),
'he': (CAT, u" "),
'hi': (BACK,u" "),
'hr': (CAT, u"Izabrani lanci"),
'hsb':(CAT, u"Ekscelentny"),
'hu': (CAT, u"Kiemelt cikkek"),
'hy': (BACK,u" "),
'ia': (CAT, u"Wikipedia:Articulos eminente"),
'id': (BACK, u"Featured article"),
#'id': (CAT, u"Artikel bagus utama"),
'is': (CAT, u"Wikipedia:rvalsgreinar"),
'it': (CAT, u"Voci in vetrina"),
'ja': (BACK,u"Featured article"),
'ka': (CAT, u" "),
'km': (BACK,u""),
'kn': (BACK,u" "),
'ko': (CAT, u" "),
'ksh':(CAT, u"Exzlenter Aatikkel"),
'kv': (CAT, u": "),
'la': (CAT, u"Paginae mensis"),
'li': (CAT, u"Wikipedia:Sjterartikele"),
'lmo':(CAT, u"Articol ben faa"),
'lo': (CAT, u""),
'lt': (CAT, u"Vikipedijos pavyzdiniai straipsniai"),
'lv': (CAT, u"Vrtgi raksti"),
#'lv': (CAT, u"Nedas raksti"),
'mk': (BACK, u""),
'ml': (BACK,u"Featured"),
'mr': (CAT, u" "),
'ms': (BACK,u"Rencana pilihan"),
'nah':(BACK,u"Featured article"),
'nds-nl': (BACK, u"Etelazie"),
'nl': (CAT, u"Wikipedia:Etalage-artikelen"),
'nn': (BACK,u"God artikkel"),
'no': (CAT, u"Utmerkede artikler"),
'nv': (CAT, u"Naaltsoos nizhngo lyaag"),
'oc': (CAT, u"Article de qualitat"),
'pl': (CAT, u"Artykuy na medal"),
'pt': (CAT, u"!Artigos destacados"),
'ro': (CAT, u"Articole de calitate"),
'ru': (BACK, u" "),
'sco':(CAT, u"Featurt"),
'sh': (CAT, u"Izabrani lanci"),
'simple': (CAT, u"Very good articles"),
'sk': (BACK,u"Perfektn lnok"),
'sl': (CAT, u"Vsi izbrani lanki"),
'sq': (BACK,u"Artikulli perfekt"),
'sr': (CAT, u""),
'sv': (CAT, u"Wikipedia:Utmrkta artiklar"),
'sw': (BACK,u"Makala_nzuri_sana"),
'szl':(CAT, u"Wyrne artikle"),
'ta': (CAT, u" "),
'te': (CAT, u""),
'th': (BACK,u""),
'tl': (BACK,u"Napiling artikulo"),
'tr': (BACK,u"Sekin madde"),
'tt': (CAT, u" "),
'uk': (CAT, u" "),
'ur': (CAT, u" "),
'uz': (CAT, u"Vikipediya:Tanlangan maqolalar"),
'vec':(BACK,u"Vetrina"),
'vi': (CAT, u"Bi vit chn lc"),
'vo': (CAT, u"Yegeds gudik"),
'wa': (CAT, u"Raspepy rtike"),
'yi': (CAT, u" "),
'yo': (BACK,u"yk ptk"),
'zh': (CAT, u""),
'zh-classical': (CAT, u""),
'zh-yue': (BACK, u""),
}
good_name = {
'ar': (CAT, u" "),
'ca': (CAT, u"Llista d'articles bons"),
'cs': (CAT, u"Wikipedie:Dobr lnky"),
'da': (CAT, u"Gode artikler"),
'de': (CAT, u"Wikipedia:Lesenswert"),
#'dsb':(CAT, u"Naraenje za pgdnoenje"),
'en': (CAT, u"Wikipedia good articles"),
'eo': (CAT, u"Legindaj artikoloj"),
'es': (CAT, u"Wikipedia:Artculos buenos"),
'et': (CAT, u"Head artiklid"),
'fa': (CAT, u" "),
'fi': (CAT, u"Hyvt artikkelit"),
'fr': (CAT, u"Bon article"),
'hsb':(CAT, u"Namjet za pohdnoenje"),
'id': (BACK,u"Artikel bagus"),
#'id': (CAT, u"Artikel bagus"),
'is': (CAT, u"Wikipedia:Gagreinar"),
'ja': (CAT, u""),
'ksh':(CAT, u"Joode Aatikkel"),
'lt': (CAT, u"Vertingi straipsniai"),
'lv': (CAT, u"Labi raksti"),
'no': (CAT, u"Anbefalte artikler"),
'oc': (CAT, u"Bon article"),
'pl': (CAT, u"Dobre artykuy"),
'ro': (BACK, u"Articol bun"),
'ru': (CAT, u": "),
'simple': (CAT, u"Good articles"),
'sr': (BACK,u" "),
'sv': (CAT, u"Wikipedia:Bra artiklar"),
'tr': (BACK,u"Kaliteli madde"),
'uk': (CAT, u": "),
'uz': (CAT, u"Vikipediya:Yaxshi maqolalar"),
'yi': (CAT, u" "),
'zh': (CAT, u""),
'zh-classical': (CAT, u""),
}
lists_name = {
'ar': (BACK, u' '),
'da': (BACK, u'FremragendeListe'),
'de': (BACK, u'Informativ'),
'en': (BACK, u'Featured list'),
'fa': (BACK, u" "),
'id': (BACK, u'Featured list'),
'ja': (BACK, u'Featured List'),
'ksh':(CAT, u"Joode Le"),
'no': (BACK, u'God liste'),
'pl': (BACK, u'Medalista'),
'pt': (BACK, u'Anexo destacado'),
'ro': (BACK, u'List de calitate'),
'ru': (BACK, u' '),
'tr': (BACK, u'Sekin liste'),
'uk': (BACK, u' '),
'vi': (BACK, u'Sao danh sch chn lc'),
'zh': (BACK, u'Featured list'),
'da': (BACK, u'FremragendeListe'),
}
former_name = {
'th': (CAT, u""),
'pt': (CAT,u"!Ex-Artigos_destacados"),
'es': (CAT,u"Wikipedia:Artculos anteriormente destacados"),
'hu': (CAT,u"Korbbi kiemelt cikkek"),
'ru': (CAT, u": "),
'ca': (CAT, u"Arxiu de propostes de la retirada de la distinci"),
'es': (CAT, u"Wikipedia:Artculos anteriormente destacados"),
'tr': (CAT, u"Vikipedi eski sekin maddeler"),
'zh': (CAT, u"Wikipedia_former_featured_articles"),
}
# globals
interactive=0
nocache=0
afterpage=u"!"
cache={}
def featuredArticles(site, pType):
arts=[]
try:
if pType == 'good':
method=good_name[site.lang][0]
elif pType == 'former':
method=former_name[site.lang][0]
elif pType == 'list':
method=lists_name[site.lang][0]
else:
method=featured_name[site.lang][0]
except KeyError:
wikipedia.output(u'Error: language %s doesn\'t has %s category source.' % (site.lang, feature))
return arts
if pType == 'good':
name=good_name[site.lang][1]
elif pType == 'former':
name=former_name[site.lang][1]
elif pType == 'list':
name=lists_name[site.lang][1]
else:
name=featured_name[site.lang][1]
raw=method(site, name)
for p in raw:
if p.namespace()==0: # Article
arts.append(p)
elif p.namespace()==1 and site.lang <> 'el': # Article talk (like in English)
arts.append(wikipedia.Page(p.site(), p.titleWithoutNamespace()))
wikipedia.output('\03{lightred}** wikipedia:%s has %i %s articles\03{default}' % (site.lang, len(arts), pType))
return arts
def findTranslated(page, oursite=None, quiet=False):
if not oursite:
oursite=wikipedia.getSite()
if page.isRedirectPage():
page = page.getRedirectTarget()
try:
iw=page.interwiki()
except:
wikipedia.output(u"%s -> no interwiki, giving up" % page.title())
return None
ourpage=None
for p in iw:
if p.site()==oursite:
ourpage=p
break
if not ourpage:
if not quiet:
wikipedia.output(u"%s -> no corresponding page in %s" % (page.title(), oursite))
return None
if not ourpage.exists():
wikipedia.output(u"%s -> our page doesn't exist: %s" % (page.title(), ourpage.title()))
return None
if ourpage.isRedirectPage():
ourpage = ourpage.getRedirectTarget()
wikipedia.output(u"%s -> corresponding page is %s" % (page.title(), ourpage.title()))
if ourpage.namespace() != 0:
wikipedia.output(u"%s -> not in the main namespace, skipping" % page.title())
return None
if ourpage.isRedirectPage():
wikipedia.output(u"%s -> double redirect, skipping" % page.title())
return None
if not ourpage.exists():
wikipedia.output(u"%s -> page doesn't exist, skipping" % ourpage.title())
return None
try:
iw=ourpage.interwiki()
except:
return None
backpage=None
for p in iw:
if p.site()==page.site():
backpage=p
break
if not backpage:
wikipedia.output(u"%s -> no back interwiki ref" % page.title())
return None
if backpage==page:
# everything is ok
return ourpage
if backpage.isRedirectPage():
backpage = backpage.getRedirectTarget()
if backpage==page:
# everything is ok
return ourpage
wikipedia.output(u"%s -> back interwiki ref target is %s" % (page.title(), backpage.title()))
return None
def getTemplateList (lang, pType):
if pType == 'good':
try:
templates = template_good[lang]
templates+= template_good['_default']
except KeyError:
templates = template_good['_default']
elif pType == 'former':
try:
templates = template[lang]
templates+= template['_default']
except KeyError:
templates = template['_default']
elif pType == 'list':
try:
templates = template_lists[lang]
templatest+= template_lists['_default']
except KeyError:
templates = template_lists['_default']
else:
try:
templates = template[lang]
templates+= template['_default']
except KeyError:
templates = template['_default']
return templates
def featuredWithInterwiki(fromsite, tosite, template_on_top, pType, quiet, dry = False):
if not fromsite.lang in cache:
cache[fromsite.lang]={}
if not tosite.lang in cache[fromsite.lang]:
cache[fromsite.lang][tosite.lang]={}
cc=cache[fromsite.lang][tosite.lang]
if nocache:
cc={}
templatelist = getTemplateList(tosite.lang, pType)
findtemplate = '(' + '|'.join(templatelist) + ')'
re_Link_FA=re.compile(ur"\{\{%s\|%s\}\}" % (findtemplate.replace(u' ', u'[ _]'), fromsite.lang), re.IGNORECASE)
re_this_iw=re.compile(ur"\[\[%s:[^]]+\]\]" % fromsite.lang)
arts=featuredArticles(fromsite, pType)
pairs=[]
for a in arts:
if a.title()<afterpage:
continue
if u"/" in a.title() and a.namespace() != 0:
wikipedia.output(u"%s is a subpage" % a.title())
continue
if a.title() in cc:
wikipedia.output(u"(cached) %s -> %s"%(a.title(), cc[a.title()]))
continue
if a.isRedirectPage():
a=a.getRedirectTarget()
try:
if not a.exists():
wikipedia.output(u"source page doesn't exist: %s" % a.title())
continue
atrans = findTranslated(a, tosite, quiet)
if pType!='former':
if atrans:
text=atrans.get()
m=re_Link_FA.search(text)
if m:
wikipedia.output(u"(already done)")
else:
# insert just before interwiki
if (not interactive or
wikipedia.input(u'Connecting %s -> %s. Proceed? [Y/N]'%(a.title(), atrans.title())) in ['Y','y']
):
m=re_this_iw.search(text)
if not m:
wikipedia.output(u"no interwiki record, very strange")
continue
site = wikipedia.getSite()
if pType == 'good':
comment = wikipedia.setAction(wikipedia.translate(site, msg_good) % (fromsite.lang, a.title()))
elif pType == 'list':
comment = wikipedia.setAction(wikipedia.translate(site, msg_lists) % (fromsite.lang, a.title()))
else:
comment = wikipedia.setAction(wikipedia.translate(site, msg) % (fromsite.lang, a.title()))
### Moving {{Link FA|xx}} to top of interwikis ###
if template_on_top == True:
# Getting the interwiki
iw = wikipedia.getLanguageLinks(text, site)
# Removing the interwiki
text = wikipedia.removeLanguageLinks(text, site)
text += u"\r\n{{%s|%s}}\r\n"%(templatelist[0], fromsite.lang)
# Adding the interwiki
text = wikipedia.replaceLanguageLinks(text, iw, site)
### Placing {{Link FA|xx}} right next to corresponding interwiki ###
else:
text=(text[:m.end()]
+ (u" {{%s|%s}}" % (templatelist[0], fromsite.lang))
+ text[m.end():])
if not dry:
try:
atrans.put(text, comment)
except wikipedia.LockedPage:
wikipedia.output(u'Page %s is locked!' % atrans.title())
cc[a.title()]=atrans.title()
else:
if atrans:
text=atrans.get()
m=re_Link_FA.search(text)
if m:
# insert just before interwiki
if (not interactive or
wikipedia.input(u'Connecting %s -> %s. Proceed? [Y/N]'%(a.title(), atrans.title())) in ['Y','y']
):
m=re_this_iw.search(text)
if not m:
wikipedia.output(u"no interwiki record, very strange")
continue
site = wikipedia.getSite()
comment = wikipedia.setAction(wikipedia.translate(site, msg_former) % (fromsite.lang, a.title()))
name=templatelist[0]
name2=name[0].lower()+name[1:]
text=text.replace(u"{{%s|%s}}" %(name, fromsite.lang),'',1)
text=text.replace(u"{{%s|%s}}" %(name2, fromsite.lang),'',1)
if not dry:
try:
atrans.put(text, comment)
except wikipedia.LockedPage:
wikipedia.output(u'Page %s is locked!' % atrans.title())
else:
wikipedia.output(u"(already done)")
cc[a.title()]=atrans.title()
except wikipedia.PageNotSaved, e:
wikipedia.output(u"Page not saved")
if __name__=="__main__":
template_on_top = False
featuredcount = False
fromlang=[]
processType = 'featured'
doAll = False
part = False
quiet = False
dry = False
for arg in wikipedia.handleArgs():
if arg == '-interactive':
interactive=1
elif arg == '-nocache':
nocache=1
elif arg.startswith('-fromlang:'):
fromlang=arg[10:].split(",")
part = True
elif arg == '-fromall':
doAll = True
elif arg.startswith('-after:'):
afterpage=arg[7:]
elif arg == '-top':
template_on_top = True
elif arg == '-count':
featuredcount = True
elif arg == '-good':
processType = 'good'
elif arg == '-lists':
processType = 'list'
elif arg == '-former':
processType = 'former'
elif arg == '-quiet':
quiet = True
elif arg == '-dry':
dry = True
if part:
try:
# BUG: range with zh-min-nan (3 "-")
if len(fromlang)==1 and fromlang[0].index("-")>=0:
ll1,ll2=fromlang[0].split("--",1)
if not ll1: ll1=""
if not ll2: ll2="zzzzzzz"
if processType == 'good':
fromlang=[ll for ll in good_name.keys() if ll>=ll1 and ll<=ll2]
elif processType == 'list':
fromlang=[ll for ll in good_lists.keys() if ll>=ll1 and ll<=ll2]
elif processType == 'former':
fromlang=[ll for ll in former_lists.keys() if ll>=ll1 and ll<=ll2]
else:
fromlang=[ll for ll in featured_name.keys() if ll>=ll1 and ll<=ll2]
except:
pass
if doAll:
if processType == 'good':
fromlang=good_name.keys()
elif processType == 'list':
fromlang=lists_name.keys()
elif processType == 'former':
fromlang=former_name.keys()
else:
fromlang=featured_name.keys()
filename="cache/" + processType
try:
cache=pickle.load(file(filename,"rb"))
except:
cache={}
if not fromlang:
wikipedia.showHelp('featured')
sys.exit(1)
fromlang.sort()
#test whether this site has template enabled
hasTemplate = False
if not featuredcount:
for tl in getTemplateList(wikipedia.getSite().lang, processType):
t = wikipedia.Page(wikipedia.getSite(), u'Template:'+tl)
if t.exists():
hasTemplate = True
break
try:
for ll in fromlang:
fromsite = wikipedia.getSite(ll)
if featuredcount:
featuredArticles(fromsite, processType)
elif not hasTemplate:
wikipedia.output(u'\nNOTE: %s arcticles are not implemented at %s-wiki.' % (processType, wikipedia.getSite().lang))
wikipedia.output('Quitting program...')
break
elif fromsite != wikipedia.getSite():
featuredWithInterwiki(fromsite, wikipedia.getSite(),
template_on_top, processType, quiet, dry)
except KeyboardInterrupt:
wikipedia.output('\nQuitting program...')
finally:
wikipedia.stopme()
if not nocache:
pickle.dump(cache,file(filename,"wb"))
|