Utente:BimBot/Scripts: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
nuova versione!!!!!
Riga 1:
Copiate gente, copiate! (<small>Che poi va a fuoco il computer...</small>) :-D
 
== <tt>sistemaredirect.py</tt> v. 3.0 ==
<pre>
# -*- coding: utf-8 -*-
 
################################################################
Riga 15:
 
def main():
args = wikipedia.handleArgs()
while 1:
while 1:
all = 0;
redirectLinks = dict()
name = wikipedia.input(u'Inserisci il nome del redirect [punto per terminare]:')
all = 0;
if name == '.':
ic = inputchoice()
break
if ic == u'.':
page = wikipedia.Page(wikipedia.getSite(), name)
break
try:
if ic == u'P':
page.isRedirectPage
name = wikipedia.input(u'Inserisci il nome della pagina da cui ricavare i redirect [punto per terminare]:')
dest = wikipedia.Page(wikipedia.getSite(), page.getRedirectTarget())
if name == u'.':
print dest
break
ref = page.getReferences()
page = wikipedia.Page(wikipedia.getSite(), name)
for s in ref:
redirectLinks = getlinkstoredirectstopage(page)
oldtext = s.get()
else:
print s
name = wikipedia.input(u'Inserisci il nome del redirect [punto per terminare]:')
newtext = sistema(oldtext, page.title(), dest.title())
if name == u'.':
wikipedia.showDiff(oldtext, newtext)
break
if not all:
page = wikipedia.Page(wikipedia.getSite(), name)
choice = wikipedia.inputChoice(u'Vuoi veramente modificare?', ['Yes', 'No', 'all'], ['y', 'N', 'a'], 'N')
redirectLinks[page.title()] = page.getReferences()
if choice in ['A', 'a']:
for i in redirectLinks:
all = 1
print i
choice = 'Y'
page = wikipedia.Page(wikipedia.getSite(), i)
if choice in ['Y', 'y'] or all:
dest = page.getRedirectTarget()
wikipedia.setAction(u'Correggo i link che puntano al redirect "%s"' % page.title())
ref = redirectLinks[i]
s.put(newtext)
for j in ref:
except wikipedia.IsNotRedirectPage:
oldtext = j.get()
print page.isRedirectPage()
print j
print u"Non e' un redirect!"
lnks = sgamalink(i, oldtext)
continue
for k in lnks:
except wikipedia.NoPage:
if u'|' in k:
print u'La pagina non esiste!'
regex = u"\[\[%s\|(.*?)\]\]" % i
wikipedia.stopme();
p = re.compile(regex, re.IGNORECASE)
lst = re.findall(p, oldtext)
choice = u"[[" + dest.title() + u"|" + lst[0] + u"]]"
else:
choice = linkchoice(dest.title(), i)
if choice == u'.':
exit()
newtext = sistema(oldtext, page.title(), choice)
wikipedia.showDiff(oldtext, newtext)
choice = wikipedia.inputChoice(u'Posso procedere?', ['Yes', 'No'], ['y', 'N'], 'N')
if choice in ['Y', 'y']:
wikipedia.setAction(u'Correggo i link che puntano al redirect "%s"' % page.title())
j.put(newtext)
wikipedia.stopme();
 
def getlinkstoredirectstopage(page):
def sistema(text, oldtitle, newtitle):
try:
regex = u'\[\[%s\|' % oldtitle
redirectLinks = dict()
p = re.compile(regex, re.IGNORECASE)
ref = page.getReferences()
nuovotesto = "[[%s|" % newtitle
redirectList=list()
text = re.sub(p, nuovotesto, text)
for i in ref:
regex = u'\[\[%s\]\]' % oldtitle
if i.isRedirectPage():
p = re.compile(regex, re.IGNORECASE)
redirectLinks[i.title()] = i.getReferences()
nuovotesto = "[[%s|%s]]" % (newtitle, oldtitle)
return redirectLinks;
text = re.sub(p, nuovotesto, text)
except wikipedia.IsNotRedirectPage:
return text
print page.isRedirectPage()
print u"Non e' un redirect!"
return 0
except wikipedia.NoPage:
print u'La pagina non esiste!'
return 0
 
def inputchoice():
choice = wikipedia.inputChoice(u"Vuoi inserire il nome di un redirect o di una pagina a cui linkano dei redirect? [punto per terminare]", [u'Redirect', u'Page', u'.'], [u'R', u'p', u'.'], u'R')
if choice == u'.':
return u'.'
elif choice in [u'P', u'p']:
return u'P'
else:
return u'R'
 
def linkchoice(newpage, oldpage):
scelte = [u"[[" + newpage + u"]]", u"[[" + newpage + u"|" + newpage[0].lower() + newpage[1:] + u"]]", u"[[" + newpage + u"|" + oldpage + u"]]", u"[[" + newpage + u"|" + oldpage[0].lower() + oldpage[1:] + u"]]", u'.']
sceltecopy = scelte
choice = wikipedia.inputChoice(u"Scegli una delle seguenti alternative per il link: [punto per terminare]", sceltecopy, [u'1', u'2', u'3', u'4', u'.'], u'1')
if choice == u'.':
return u'.'
return scelte[int(choice)-1][:len(scelte[int(choice)-1])-4]
 
def sgamalink(oldtitle, oldtext):
regex = u"\[\[%s(.*?)\]\]" % oldtitle
p = re.compile(regex, re.IGNORECASE)
lst = re.findall(p, oldtext)
return lst
 
def sistema(text, oldtitle, choice):
regex = u"\[\[%s.*?\]\]" % oldtitle
p = re.compile(regex, re.IGNORECASE)
text = re.sub(p, text, choice)
return text
 
if __name__==u"__main__":
main()
 
if __name__=="__main__":
main()
</pre>