Utente:BimBot/Scripts: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
PAWBot (discussione | contributi)
m Fix, replaced: <source → <syntaxhighlight (17), </source → </syntaxhighlight (17)
 
(7 versioni intermedie di 2 utenti non mostrate)
Riga 2:
Copiate gente, copiate! (<small>Che poi va a fuoco il computer...</small>) :-D
 
== <ttkbd>redirectlinks.py</ttkbd> ==
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 71:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>lonelypages.py</ttkbd> ==
Prende le pagine da [[Speciale:Lonelypages]], verifica che siano veramente orfane e inserisce l'avviso in quelle che non lo hanno già.
Script spostato [http://www.botwiki.sno.cc/wiki/Python:Lonelypages.py qui].
 
== <ttkbd>proxyaperti.py</ttkbd> ==
Questo script fa semplicemente un edit in una pagina.
In verità serve per scovare i proxy aperti, agendo da sloggati.
Riga 83:
Utilizzabile solo da personale addestrato ;-)
 
<sourcesyntaxhighlight lang="python">
#! -*- coding: utf-8 -*-
 
Riga 98:
pagina.put(newtxt)
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>lavorosporco.py</ttkbd> ==
Questo script serve per aggiornare le [[Progetto:Coordinamento/Statistiche manutenzioni|statistiche del lavoro sporco]].
 
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 159:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>statistichemanutenzioni.py</ttkbd> ==
Questo script serve per aggiornare le statistiche manutenzioni dei progetti tematici. Andrebbe generalizzato ed unito con lavorosporco.py.
 
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 208:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>frazioni.py</ttkbd> ==
Questo script serve per aggiungere <ttkbd><nowiki>{{Tmp|Frazione}}</nowiki></ttkbd> a tutte le frazioni che non contengono il template {{Tl|Frazione}}.
 
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 248:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>monitoraggioimmagini.py</ttkbd> ==
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- utf-8 -*-
Riga 289:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>aggiornaCitazioniPP.py</ttkbd> ==
Script usato per aggiornare le citazioni del giorno sulla pagina principale.
 
<sourcesyntaxhighlight lang="python">
#!/usr/bin/python
# -*- coding: utf-8 -*-
Riga 349:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>numero_voci_vetrina.py</ttkbd> ==
Aggiorna il template contenente il numero di voci in vetrina.
 
<sourcesyntaxhighlight lang="python">
# -*- coding: utf8 -*-
import wikipedia, catlib
Riga 390:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>codici_autori_fantascienza.py</ttkbd> ==
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 437:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>articoli_defaultsort.py</ttkbd> ==
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 506:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>newsPedia.py</ttkbd> ==
Prende le ultime notizie da 'news e le sbatte su 'pedia.
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 582:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>copyviolInversi.py</ttkbd> ==
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 666:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>importa_asteroidi.py</ttkbd> ==
<sourcesyntaxhighlight lang="python">
# -*- coding: utf-8 -*-
import wikipedia, re, sys, codecs
Riga 731:
 
#K07B19V 15.7 0.15 K06CV 19.17898 347.71274 101.16774 10.08579 0.0550460 0.19108058 2.9853254 E2007-B48 13 1 16 days 0.37 MPC 0000 2007 BV19 20070124
</syntaxhighlight>
</source>
 
=== <ttkbd>modello_asteroide.txt</ttkbd> ===
<pre>
{{S|asteroidi}}
Riga 758:
</pre>
 
== <ttkbd>discussioneanonimi3.py</ttkbd> ==
 
<sourcesyntaxhighlight lang="python">
# -*- coding: utf-8 -*-
import wikipedia, re, commands
Riga 799:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <ttkbd>prefissiTelefonici.py</ttkbd> ==
<sourcesyntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Riga 815:
def main():
all = False
args = wikipedia.handleArgs()
startWith=""
for argh in args:
if argh.startswith("-start:"):
startWith = argh[len("-start:"):]
mySite = wikipedia.getSite(code='it', fam='wikipedia')
cat = catlib.Category(mySite, "Categoria:Prefissi telefonici italiani")
gen = pagegenerators.CategorizedPageGenerator(cat, False, startWith)
for p in gen:
voceOk = 1
try:
oldText = p.get()
Line 827 ⟶ 833:
except wikipedia.IsRedirectPage:
p = p.getRedirectTarget()
oldText = currentPagep.get()
# Per sicurezza se non esegue tutti i match salta la voce
if not re.search("== ?[Nn]ote ?==", oldText):
m =if re.matchsearch("^(\d+)== ?[Nn]ote ?==", p.title()oldText);:
continue
prefisso = m.group(1)
newText = oldText
# Ottengo il prefisso "nudo" dal titolo
wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
m = %re.match("^(\d+)", p.title());
if m == None:
continue
newText = re.sub(",", note1 + ",", newText, 1)
prefisso = m.group(1)
newText = re.sub("\.\s*\{\{[Cc]ompartimento", " " + note2 % prefisso + ".\n\n" + sezioneNote + "\n{{Compartimento", newText, 1)
newText = oldText
newText = re.sub("\{\{[Ff](\|.*?)\}\}\s+", "", newText, 1)
# Sostituzione 1
wikipedia.showDiff(oldText, newText)
m = re.subn(r"il \[\[prefisso telefonico\]\] del \[\[distretto telefonico\|distretto\]\] di \[\[(.*?)\]\],",
if not all:
r"il [[prefisso telefonico]] del [[distretto telefonico|distretto]] di [[\1]]" + note1 + ",",
choice = wikipedia.inputChoice(u"Modificare?", ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
else:newText, 1)
if m[1]==0:
choice = 'y'
continue
if choice in ['A', 'a']:
else:
all = True
choicenewText = 'y'm[0]
if choice in ['Y', 'y']:
# Sostituzione 2
p.put(newText, minorEdit=False, comment=oggetto)
m = re.subn(r"Il distretto di (.*?) comprende (.*?)\.\s+\{\{[Cc]ompartimento",
r'Il distretto di \1 comprende \2 ' + note2 % prefisso + ".\n\n" + sezioneNote + "\n{{Compartimento",
newText, 1)
if m[1]==0:
continue
else:
newText = m[0]
# Sostituzione 3
newText = re.sub("\{\{[Ff](\|.*?)\}\}\s+", "", newText, 1)
# Visualizza le differenze, chiede e salva
wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% p.title())
wikipedia.showDiff(oldText, newText)
if not all:
choice = wikipedia.inputChoice(u"Modificare?",
['Yes', 'No', 'All', "Quit"],
['y', 'N', 'a', 'q'], 'N')
else:
choice = 'y'
if choice in ['A', 'a']:
all = True
choice = 'y'
if choice in ['Y', 'y']:
p.put_async(newText, minorEdit=False, comment=oggetto)
elif choice in ['Q', 'q']:
return
if __name__ == "__main__":
Line 856 ⟶ 890:
finally:
wikipedia.stopme()
</syntaxhighlight>
</source>
 
== <code>vocicorrelate.py</code> ==
 
<syntaxhighlight lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Lo script rimuove i piped links e i corsivi dai link nelle "Voci correlate".
# Si lancia con gli argomenti supportati da pagegenerators.py
#
# Esempi:
# $ python vocicorrelate.py -catr:Informatica
# $ python vocicorrelate.py -start:!
#
# Autore: Pietrodn
 
import wikipedia, pagegenerators, re
 
oggetto = u"Uniformo le [[Aiuto:Voci correlate|voci correlate]]"
 
def main():
all = False
args = wikipedia.handleArgs()
genf = pagegenerators.GeneratorFactory();
for argh in args:
genf.handleArg(argh)
mySite = wikipedia.getSite(code='it', fam='wikipedia')
gen = genf.getCombinedGenerator()
if not gen:
return
for p in gen:
try:
oldText = p.get()
except wikipedia.NoPage:
wikipedia.output(currentPage.title() + " does not exist!")
continue
except wikipedia.IsRedirectPage:
p = p.getRedirectTarget()
oldText = p.get()
newText = oldText
# Cerco il contenuto della sezione voci correlate:
# inizia dal titolo di sezione e finisce alla prima riga che non inizia con un punto elenco
m = re.search(r"(?s)==\s*[Vv]oci correlate\s*==(.*?)\n[^*]", oldText)
# Niente "voci correlate"? Passo alla prossima voce
if not m:
continue
vcorrTextOld = m.group(1)
vcorrText = vcorrTextOld
# Tolgo il corsivo
vcorrText = re.sub(r"''\[\[(.*?)\]\]''", r"[[\1]]", vcorrText);
# Tolgo i piped link
vcorrText = re.sub(r"\[\[(.*?)\|(.*?)\]\]", r"[[\1]]", vcorrText);
# Se non ho effettuato modifiche nella sezione "voci correlate", avanti alla prossima voce
if vcorrText == vcorrTextOld:
continue
# Re-innesto la sezione voci correlate al suo posto nella voce
newText = re.sub(r"(?s)==\s*[Vv]oci correlate\s*==(.*?)(\n[^*])", r"== Voci correlate ==" + vcorrText + r"\2", oldText)
# Visualizza le differenze, chiede e salva
wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% p.title())
wikipedia.showDiff(oldText, newText)
if not all:
choice = wikipedia.inputChoice(u"Modificare?",
['Yes', 'No', 'All', "Quit"],
['y', 'N', 'a', 'q'], 'N')
else:
choice = 'y'
if choice in ['A', 'a']:
all = True
choice = 'y'
if choice in ['Y', 'y']:
p.put_async(newText, minorEdit=True, comment=oggetto)
elif choice in ['Q', 'q']:
return
if __name__ == "__main__":
try:
main()
finally:
wikipedia.stopme()
</syntaxhighlight>
 
== Eliminazione parametro "Stato" dal [[Template:Edificio religioso]] ==
 
Codice da inserire in <kbd>user-fixes.py</kbd>:
 
<syntaxhighlight lang="python">
import re
 
def EdRel(match):
# Le parentesi devono essere bilanciate, e le prime parentesi graffe trovate non devono essere chiuse
aperte = re.findall(ur'\{\{', match.group(1))
chiuse = re.findall(ur'\}\}', match.group(1))
if (len(aperte) == len(chiuse)) and (not re.match("(?s)[^{}]*\}\}.*", match.group(1))):
return ur"{{Edificio religioso" + match.group(1)
else:
return match.group() # Unchanged
fixes['EdificioReligioso'] = {
'regex': True,
'msg': {
'_default':u'Eliminazione parametro obsoleto del [[Template:Edificio religioso]] ([[Wikipedia:Bot/Richieste#Eliminazione_campo_dal_template_.22Edificio_religioso.22|richiesta]])',
},
'replacements': [
(ur"(?s)\{\{\s*[Ee]dificio[ _]religioso(.*?)\|\s*[Ss]tato\s*=\s*([^|\n]*)\n", EdRel),
],
'exceptions': {
'inside-tags': ['comment', 'header', 'pre', 'source', 'ref', 'table', 'hyperlink', 'gallery', 'link', 'interwiki' ],
}
}
</syntaxhighlight>