Utente:BimBot/Scripts
Copiate gente, copiate! :-D
sistemaredirect.py
# -*- coding: utf-8 -*- ################################################################ # Questo bot permette di modificare i link ad un redirect # # perche' puntino direttamente alla pagina giusta. # # Usa il framework pywikipedia. # ################################################################ import urllib, re import wikipedia def main(): while 1: all = 0; name = wikipedia.input(u'Inserisci il nome del redirect [punto per terminare]:') if name == '.': break page = wikipedia.Page(wikipedia.getSite(), name) try: page.isRedirectPage dest = wikipedia.Page(wikipedia.getSite(), page.getRedirectTarget()) print dest ref = page.getReferences() for s in ref: oldtext = s.get() print s newtext = sistema(oldtext, page.title(), dest.title()) wikipedia.showDiff(oldtext, newtext) if not all: choice = wikipedia.inputChoice(u'Vuoi veramente modificare?', ['Yes', 'No', 'all'], ['y', 'N', 'a'], 'N') if choice in ['A', 'a']: all = 1 choice = 'Y' if choice in ['Y', 'y']: wikipedia.setAction(u'Correggo i link che puntano al redirect "%s"' % page.title()) s.put(newtext) except wikipedia.IsNotRedirectPage: print page.isRedirectPage() print u"Non e' un redirect!" continue except wikipedia.NoPage: print u'La pagina non esiste!' wikipedia.stopme(); def sistema(text, oldtitle, newtitle): regex = u'\[\[%s' % oldtitle p = re.compile(regex, re.IGNORECASE) nuovotesto = "[[%s" % newtitle new = re.sub(p, nuovotesto, text) return new if __name__=="__main__": main()