Utente:TekBot/sysredir.py

# -*- coding: utf-8  -*-

################################################################
# Questo bot permette di modificare i link ad un redirect      #
# perche' puntino direttamente alla pagina giusta.             #
# Usa il framework pywikipedia.                                #
# Thanks to Civvi                                              #
################################################################

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'] or all:
     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()

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.