Utente:BimBot/Scripts
Da Wikipedia, l'enciclopedia libera.
Copiate gente, copiate! (Che poi va a fuoco il computer...) :-D
Indice |
[modifica] sistemaredirect.py v. 3.1
# -*- coding: utf-8 -*- ################################################################ # Questo bot permette di modificare i link ad un redirect # # perche' puntino direttamente alla pagina giusta. # # Usa il framework pywikipedia. # ################################################################ import wikipedia, urllib, re, sys def main(): args = wikipedia.handleArgs() while 1: redirectLinks = dict() all = 0; ic = inputchoice() if ic == u'.': safeexit() if ic == u'P': name = wikipedia.input(u'Inserisci il nome della pagina da cui ricavare i redirect [punto per terminare]:') if name == u'.': safeexit() page = wikipedia.Page(wikipedia.getSite(), name) redirectLinks = getlinkstoredirectstopage(page) else: name = wikipedia.input(u'Inserisci il nome del redirect [punto per terminare]:') if name == u'.': safeexit() page = wikipedia.Page(wikipedia.getSite(), name) redirectLinks[page.title()] = page.getReferences() for i in redirectLinks: page = wikipedia.Page(wikipedia.getSite(), i) dest = wikipedia.Page(wikipedia.getSite(), page.getRedirectTarget()) ref = redirectLinks[i] for j in ref: oldtext = j.get() lnks = sgamalink(i, oldtext) for k in lnks: print "\n" wikipedia.output("Nome del redirect: " + page.aslink()) wikipedia.output("Pagina a cui punta il redirect: " + dest.aslink()) wikipedia.output("Link in via di correzione: " + k) wikipedia.output("Pagina che contiene il link: " + j.aslink()) print "\n" if u'|' in k: regex = u"\[\[%s\|(.*?)\]\]" % i p = re.compile(regex, re.IGNORECASE) dopolink = re.search(p, oldtext) choice = "[[" + dest.title() + "|" + dopolink.group(1) + "]]" else: tmptext = sistema(oldtext, i, u"<YOUR TEXT HERE>") wikipedia.showDiff(oldtext, tmptext) choice = linkchoice(dest.title(), i) if choice == u'.': safeexit() newtext = sistema(oldtext, i, choice) wikipedia.showDiff(oldtext, newtext) choice = wikipedia.inputChoice('Posso procedere?', ['Yes', 'No'], ['y', 'N'], 'N') if choice in ['Y', 'y']: wikipedia.setAction(u'Correggo i link che puntano al redirect "%s"' % i) j.put(newtext) wikipedia.stopme(); def safeexit(): wikipedia.stopme() sys.exit() def getlinkstoredirectstopage(page): try: redirectLinks = dict() ref = page.getReferences(redirectsOnly = True) redirectList=list() for i in ref: redirectLinks[i.title()] = i.getReferences() return redirectLinks 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 = [] for scel in scelte: sceltecopy.append(u"\n"+scel) 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, choice, text) return text if __name__==u"__main__": main()
[modifica] lonelypages.py
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à.
# -*- coding: utf-8 -*- import wikipedia import re from pagegenerators import AllpagesPageGenerator args = wikipedia.handleArgs() wikiSite = wikipedia.getSite() allpages = wikiSite.lonelypages(number = 10000, repeat = True) for i in allpages: if i.isRedirectPage() or i.isDisambig(): continue refs = i.getReferences() refsList = list() for j in refs: refsList = refsList + [j] if len(refsList) == 0: regxp = ur'\{\{ *[Oo]rfan[oa]' oldtxt = i.get() if re.match(regxp, oldtxt) == None: newtxt = u'{{Orfana}}\n' + oldtxt print i wikipedia.showDiff(oldtxt, newtxt) choice = wikipedia.inputChoice(u'Pagina orfana non segnalata! Posso procedere?', [u'Yes', u'No'], [u'y', u'N'], u'N') if choice in [u'Y', u'y']: wikipedia.setAction(u'Voce orfana, +{{Orfana}}') i.put(newtxt) wikipedia.stopme()
[modifica] Il mio benvenuto.py
Da Utente:Alfiobot/benvenuto.py
###################################################### # # 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()
[modifica] proxyaperti.py
Questo script fa semplicemente un edit in una pagina. In verità serve per scovare i proxy aperti, agendo da sloggati. Occorre però crackare wikipedia.py. Utilizzabile solo da personale addestrato ;-)
#! -*- coding: utf-8 -*- import wikipedia args = wikipedia.handleArgs() pagina = wikipedia.Page(wikipedia.getSite(), args[0]) oldtxt = pagina.get() newtxt = oldtxt + '\nSono un vandalo malvagissimo. Non bloccatemi. --~~~~' wikipedia.showDiff(oldtxt, newtxt) choice = wikipedia.inputChoice('Posso procedere?', ['Yes', 'No'], ['y', 'N'], 'N') if choice in ['Y', 'y']: wikipedia.setAction('Bot anonimo per individuare proxy aperti firmato Pietrodn. Non bloccare please.') pagina.put(newtxt) wikipedia.stopme()