Usuario:BotWikisource/ElPintor/código
Apariencia
# -*- coding: utf-8 -*- from __future__ import generators import sys, re import wikipedia, pagegenerators,catlib, config import string import random class ReplaceRobot: def __init__(self, generator, acceptall = False): self.generator = generator self.acceptall = acceptall def run(self): salida=u"\n\n==%s==\n" % random.randint(1000,5000) cont=0 for page in self.generator: if page.isRedirectPage() or not page.exists() or page.namespace()!=0: continue wtext=page.get() wtitle=page.title() wikipedia.output(u"--------------------------------------------------------") wikipedia.output(u"Analizando [%s]" % wtitle) if re.search(ur"(?i)\.(jpe?g|gif|bmp|svg|png)", wtext): wikipedia.output(u"El articulo tiene imagenes, a otra cosa mariposa") continue iw=re.finditer(ur"\[\[en:(.*)\]\]", wtext) iw_en=u"" for i in iw: if not iw_en: iw_en+=i.group(1) if not iw_en: wikipedia.output(u"El articulo no tiene interwiki, :(") continue page_en=wikipedia.Page(wikipedia.Site("en", "wikipedia"), u"%s" % iw_en) try: wtext_en=page_en.get() except: wikipedia.output(u"Hubo algun fallo al acceder al interwiki") continue if not re.search(ur"(?i):.*\.(jpe?g|png)", wtext_en): wikipedia.output(u"No tenemos imagenes donde rascar, :(") continue images_en=re.finditer(ur"(?i):(.*\.(jpe?g|png))", wtext_en) salida1=u"#[[%s]]" % wtitle temp=salida1 for i in images_en: image=i.group(1) #filtro if re.search(ur"(?i)flag|bandera", image): continue page_image=wikipedia.Page(wikipedia.Site("en", "wikipedia"), u"Image:%s" % image) if page_image.exists(): wikipedia.output(u"[NO] - %s" % image) continue page_image=wikipedia.Page(wikipedia.Site("commons", "commons"), u"Image:%s" % image) if not page_image.exists(): wikipedia.output(u"[PUF] - No esta en Commons") continue else: wikipedia.output(u"[OK] - 1up") salida1+=" - [[:Image:%s|Imagen]]" % image if temp!=salida1: salida+=salida1+"\n" cont+=1 else: continue wikipedia.output(u"---->Van %s buenas<----" % str(cont)) if cont>4: subpagina=wikipedia.Page(wikipedia.Site("es", "wikipedia"), u"User:Emijrp/Commons") subpagina.put(subpagina.get()+salida,u"%s artículos más" % str(cont)) cont=0 salida=u"\n\n==%s==\n" % random.randint(1000,5000) for arg in wikipedia.handleArgs(): if arg.startswith('-file'): if len(arg) >= 6: textfilename = arg[6:] gen = pagegenerators.TextfilePageGenerator(textfilename) elif arg.startswith('-start'): if len(arg) == 6: firstPageTitle = wikipedia.input(u'Which page do you want to chage?') else: firstPageTitle = arg[7:] namespace = wikipedia.Page(wikipedia.getSite(), firstPageTitle).namespace() firstPageTitle = wikipedia.Page(wikipedia.getSite(), firstPageTitle).titleWithoutNamespace() gen = pagegenerators.AllpagesPageGenerator(firstPageTitle, namespace) preloadingGen = pagegenerators.PreloadingGenerator(gen, pageNumber = 100) bot = ReplaceRobot(preloadingGen) bot.run()