# -*- coding: utf-8 -*- import wikipedia,pagegenerators,catlib import re cat = catlib.Category(wikipedia.getSite(), 'Category:Wikipedia:Borrar (votaciones concluidas)') gen = pagegenerators.CategorizedPageGenerator(cat) # common variables avisoborrarcabecera = r"""{{archivo borrar cabecera\|(?P<article>.*?)\s?\|\s?(?P<reasons>.*?)\s?\|(?P<day>.*?)\s?\|(?P<month>.*?)\s?\|(?P<pour>.*?)\s?\|(?P<against>.*?)\s?\|(?P<conclusion>.*?)\s?\|(?P<sign>.*?)\s?}}""" avisoborrar = r"""{{Archivo borrar\|(?P<pour>.*?)\s?\|(?P<against>.*?)\s?\|(?P<conclusion>.*?)\s?\|(?P<reasons>.*?)\s?}}""" #table=[] table=u'' line=u'{| {{tablabonita}}\n' line = line + u'! artículo\n' line = line + u'! consulta\n' line = line + u'! razones\n' line = line + u'! día\n' line = line + u'! mes\n' line = line + u'! vf\n' line = line + u'! vc\n' line = line + u'! decisión\n' table = line #table.append(line) def generatorTituloParseado(gen): for i in gen: page=wikipedia.Page(wikipedia.getSite(),re.sub(ur"Wikipedia:Consultas de borrado/","",i.title())) yield page def generadorConsultasAzules(): cat = catlib.Category(wikipedia.getSite(), 'Category:Wikipedia:Borrar (votaciones concluidas)') gen = pagegenerators.CategorizedPageGenerator(cat) gen = generatorTituloParseado(gen) gen = pagegenerators.PreloadingGenerator(gen, pageNumber = 500) for page in gen: if page.exists(): page=wikipedia.Page(wikipedia.getSite(), u'Wikipedia:Consultas de borrado/'+page.title()) yield page gen = generadorConsultasAzules() gen = pagegenerators.PreloadingGenerator(gen, pageNumber = 500) for page in gen: articulo=page.title() #print '==> Analizando: '+articulo try: texto=page.get() # se comprueba si es una cabecera de las catuales, o de las antiguas avcab = re.search(avisoborrarcabecera, texto) ab_antiguo = re.search(avisoborrar, texto) # Retrieve group(s) by name article = '' reasons = '' day = '' month = '' pour = '' against = '' conclusion = '' sign = '' if avcab: article = avcab.group('article') reasons = avcab.group('reasons') day = avcab.group('day') month = avcab.group('month') pour = avcab.group('pour') against = avcab.group('against') conclusion = avcab.group('conclusion') sign = avcab.group('sign') concl=re.search("mantener", conclusion) concl2=re.search("conservar", conclusion) concl3=re.search("no borrar", conclusion) if not concl and not concl2 and not concl3: line='' line = line + u'| [[' + article + ']]\n' line = line + u'| [[' + articulo + ']]\n' line = line + u'| ' + reasons +'\n' line = line + u'| ' + day +'\n' line = line + u'| ' + month +'\n' line = line + u'| ' + pour +'\n' line = line + u'| ' + against +'\n' line = line + u'| ' + conclusion +'\n' table = table + u'\n|-----\n' + line elif ab_antiguo: pour = ab_antiguo.group('pour') against = ab_antiguo.group('against') conclusion = ab_antiguo.group('conclusion') reasons = ab_antiguo.group('reasons') concl=re.search("mantener", conclusion) concl2=re.search("conservar", conclusion) concl3=re.search("no borrar", conclusion) if not concl and not concl2 and not concl3: line='' line = line + u'| [[' + article + ']]\n' line = line + u'| [[' + articulo + ']]\n' line = line + u'| ' + reasons +'\n' line = line + u'| ' + day +'\n' line = line + u'| ' + month +'\n' line = line + u'| ' + pour +'\n' line = line + u'| ' + against +'\n' line = line + u'| ' + conclusion +'\n' table = table + u'\n|-----\n' + line #print (line) #table = table + u'\n|-----\n' + line #table.append(line) except wikipedia.NoPage: print 'no es una página' except wikipedia.IsRedirectPage: print 'es una redirección' #table.append('|}') table=table+u'|}' ap=wikipedia.Page(wikipedia.getSite(),"Usuario:Er Komandante/Consultas") ap.put(table,comment=u"Robot: Listado de consultas de borrado") wikipedia.stopme()