== <tt>lonelypages.py</tt> ==
'''Attenzione!''': questo script ha dei problemi con le disambigue.
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].
== Il mio <tt>benvenuto.py</tt> ==
Da [[Utente:Alfiobot/benvenuto.py]]
<source lang="python">
######################################################
#
# benvenuto.py
#
# Bot per dare il benvenuto agli utenti (sono diventati troppi per farlo a mano...)
#
# Scarica il log dei nuovi utenti (fino ad un limite predefinito) e, per ogni utente
# che ancora non ha pagina di discussione, crea il seguente testo:
#
# {{benvenuto|nome=<nomeutente>}}
#
# Basato sulle librerie pywikipediabot.
import urllib, re
import wikipedia
wikipedia.handleArgs()
# No. of users to check
limit = 250
# URL of the newuser log
url = "http://%s/w/index.php?title=Speciale:Log&type=newusers&user=&page=&limit=%d" % (wikipedia.getSite().hostname(), limit)
# Search regular expression to find links like this (and the class attribute is optional too)
#<a href="/w/index.php?title=Discussioni_utente:Urizon9&action=edit" class="new" title="Discussioni utente:Urizon9">Discussione</a>
regexp = '</a> \(<a href=\"/w/index.php\?title=Discussioni_utente:(.*?)&action=edit'
# Modify user-agent string
class AppURLopener(urllib.FancyURLopener):
version = "Alfiobot/1.0"
urllib._urlopener = AppURLopener()
# Modify summary text
wikipedia.setAction("benvenuto")
# Read newuser log
print "Getting newuser log (last %d new users)..." % limit
f = urllib.urlopen(url)
text = f.read()
f.close()
r = re.compile(regexp, re.UNICODE)
# Loop over the newuser log and put welcome messages on empty discussion pages
pos = 0
tutti = False
while 1:
m = r.search(text, pos)
if m == None:
break
pos = m.end()
username = m.group(1)
print "User %s needs welcome" % username
page = u'Discussioni utente:%s' % username
p = wikipedia.Page(wikipedia.getSite(), page)
# Additional check: make a get to prevent the rare case where a discussion page
# is created between the newuser log download and now.
try:
p.get()
except wikipedia.NoPage:
newtext = u'{{benve|nome={{subst:PAGENAME}}|1=--~~~~}}'
wikipedia.showDiff('', newtext)
if not tutti:
choice = wikipedia.inputChoice(u"Vuoi dare il benvenuto all'utente %s?" % username, ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
if choice in ['a', 'A']:
tutti = True
if tutti or choice in ['y', 'Y']:
p.put(newtext)
print u"User OK!"
wikipedia.stopme()
</source>
== <tt>proxyaperti.py</tt> ==
if __name__ == "__main__":
try:
main()
finally:
wikipedia.stopme()
</source>
== <tt>frazioni.py</tt> ==
Questo script serve per aggiungere <source><nowiki>{{Tmp|Frazione}}</nowiki></source> a tutte le frazioni che non contengono il template {{Tl|Frazione}},
<source lang="python">
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re, wikipedia, catlib
def main():
args = wikipedia.handleArgs()
all = False
frazTemplateRegexp = re.compile("\{\{ *([Tt]emplate: *)?[Ff]razione")
tmpTemplateRegexp = re.compile("\{\{ *([Tt]emplate: *)?[Tt]mp *\| *[Ff]razione")
frazCat = catlib.Category(wikipedia.getSite(), "Categoria:Frazioni comunali italiane")
frazList = frazCat.articles(recurse=True)
for currentFraz in frazList:
try:
oldtxt = currentFraz.get()
except wikipedia.IsRedirectPage:
continue
if (re.search(frazTemplateRegexp, oldtxt) != None) or (re.search(tmpTemplateRegexp, oldtxt) != None):
continue
wikipedia.output(">>>>> " + currentFraz.title() + " <<<<<")
newtxt = "{{Tmp|Frazione}}\n" + oldtxt
wikipedia.showDiff(oldtxt, newtxt)
if not all:
choice = wikipedia.inputChoice(u'Aggiungo la segnalazione di template mancante?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
if choice in ['A', 'a']:
all = True
if (choice in ['Y', 'y']) or all:
currentFraz.put(newtxt, unicode("Template Frazione mancante: aggiungo {{Tmp|Frazione}}"))
if __name__ == "__main__":
try:
|