Utente:BimBot/Scripts: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
→Il mio <tt>benvenuto.py</tt>: adesso mostra diff e chiede conferma |
nuovo redirectlinks.py |
||
Riga 1:
Copiate gente, copiate! (<small>Che poi va a fuoco il computer...</small>) :-D
== <tt>
<source lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#################################################################################################
# #
# redirectlinks.py #
# #
# This script corrects links to a redirect. #
# #
# Syntax: redirectlinks.py [options] #
# Options: -dest:Destpage #
# It gets all redirects which link to Destpage and corrects their references. #
# #
# -page:Redirpage #
# It corrects all the refereces of the specified redirect. #
# #
# You must specify the -page OR the -dest option. #
# #
#################################################################################################
import
def main():
args = wikipedia.handleArgs()
for argh in args:
if argh.startswith("-dest:"):
destPage = wikipedia.Page(wikipedia.getSite(), argh[6:])
redirs = destPage.getReferences(redirectsOnly = True)
if argh.startswith("-page:"):
redirs = [wikipedia.Page(wikipedia.getSite(), argh[6:])]
if not redirs[0].isRedirectPage():
raise wikipedia.IsNotRedirectPage(redirs[0])
destPage = redirs[0].linkedPages()[0]
print destPage.title()
for r in redirs:
redirRefPages = r.getReferences()
for ref in redirRefPages:
print "Correcting links in page: " + ref.title()
newtext = oldtext
linkRegexp = "\[\[" + r.title() + "(\|[^]]+)?\]\]"
ptrn = re.compile(linkRegexp, re.IGNORECASE)
linkMatch = re.search(ptrn, newtext)
while linkMatch != None:
oldLink = newtext[linkMatch.start():linkMatch.end()]
afterLink = linkMatch.group(1)
afterLink = ""
newLink = re.sub(linkRegexp, "[[" + destPage.title() + afterLink + "]]", oldLink)
choice = wikipedia.inputChoice("Replacing link " + oldLink + " to " + newLink + ".\nDo you want to change the link?", ["Accept", "Change"], ['a', 'c'], 'a')
if choice in ['C', 'c']:
linkText = wikipedia.
newLink = "[[" + destPage.title() + linkText + "]]"
newtext = newtext[:linkMatch.start()] + newLink + newtext[linkMatch.end():]
linkMatch = re.search(ptrn, newtext)
wikipedia.showDiff(oldtext, newtext)
choice = wikipedia.inputChoice(u'Modifico?', ['Yes', 'No'], ['y', 'N'], 'N')
if choice in ['Y', 'y']:
ref.put(newtext, str("Correcting links to redirect: " + r.title()))
if __name__ == '__main__': main()
</source>
== <tt>lonelypages.py</tt> ==
Line 122 ⟶ 71:
Prende le pagine da [[Speciale:Lonelypages]], verifica che siano veramente orfane e inserisce l'avviso in quelle che non lo hanno già.
<source lang="python">
# -*- coding: utf-8 -*-
Line 151 ⟶ 100:
i.put(newtxt)
wikipedia.stopme()
</
== Il mio <tt>benvenuto.py</tt> ==
Da [[Utente:Alfiobot/benvenuto.py]]
<source lang="python">
######################################################
#
Line 234 ⟶ 183:
print u"User OK!"
wikipedia.stopme()
</
== <tt>proxyaperti.py</tt> ==
Line 242 ⟶ 191:
Utilizzabile solo da personale addestrato ;-)
<source lang="python">
#! -*- coding: utf-8 -*-
Line 257 ⟶ 206:
pagina.put(newtxt)
wikipedia.stopme()
</
|