Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.
UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.
Python:Wikidipendenza.py (standalone)
#!/usr/bin/python # -*- coding: iso-8859-1 -*- """ Piccolo script che serve per fare il test della Wikidipendenza senza carta e penna :) Inoltre il bello è che ogni volta, prima di iniziare a fare le domande il bot ricaricare tutte quelle presenti quindi avrete sempre le domande aggiornate e in tempo reale ;) l'unico difetto è che non ci saranno eventuali wikilink ma le parentesi quadre, che rendono comunque comprensibile il discorso :) Se date come input: wikidipendenza.py -totale e lo script vi stamperà il totale (ovvero quanti punti potete fare al massimo :) ) Quindi, divertitevi :) Filnik """ # # wikidipendeza.py 1.0 # # (C) Filnik it.wikipedia., 2007 # # Distributed under the terms of the MIT license. # import re, codecs import sys, urllib totale = False def handleArgs(): ''' Takes the commandline arguments, converts them to Unicode, processes all global parameters such as -lang or -log. Returns a list of all arguments that are not global. ''' global default_code, default_family # get commandline arguments args = sys.argv # get the name of the module calling this function. This is # required because the -help option loads the module's docstring and because # the module name will be used for the filename of the log. # TODO: check if the following line is platform-independent moduleName = args[0][:args[0].rindex('.')] nonGlobalArgs = [] for arg in args[1:]: if sys.platform=='win32': # stupid Windows gives parameters encoded as windows-1252, but input # encoded as cp850 arg = unicode(arg, 'windows-1252') else: # Linux uses the same encoding for both arg = unicode(arg, config.console_encoding) if arg == '-help': showHelp(moduleName) sys.exit(0) elif arg.startswith('-family:'): global default_family default_family = arg[8:] elif arg.startswith('-lang:'): global default_code default_code = arg[6:] elif arg.startswith('-putthrottle:'): put_throttle.setDelay(int(arg[13:]), absolute = True) elif arg == '-log': activateLog('%s.log' % moduleName) elif arg.startswith('-log:'): activateLog(arg[5:]) elif arg == '-nolog': global logfile logfile = None else: # the argument is not global. Let the specific bot script care # about it. nonGlobalArgs.append(arg) return nonGlobalArgs for arg in handleArgs(): if arg == '-totale': totale = True docstring = \ """ Benvenuto nel super-programma scritto da Filnik che ti permettera' di calcolare il tuo tasso di Wikipendenza in modo semplice e veloce :) Non mi resta altro che augurarti Buon Divertimento! Iniziamo! """ if totale == False: print docstring yes = ['Si', 'si', 'S', 's', 'yes', 'Yes', 'Y', 'y', 'ja'] nein = ['No', 'no', 'nein', 'N', 'n'] wiki = 'http://it.wikipedia.org/wiki/' page = 'Discussioni_utente:Filnik/sandbox' url = wiki + page # Modify user-agent string class AppURLopener(urllib.FancyURLopener): version = "Alfiobot/1.0" urllib._urlopener = AppURLopener() f = urllib.urlopen(url) f = codecs.EncodedFile(f, 'UTF-8', file_encoding='UTF-8') text = f.read() f.close() regexp = '<li>( |_|)(.*?)\? \(([0-9]|[0-9][0-9])\)</li>' r = re.compile(regexp, re.UNICODE) punti = 0 pos = 0 parola_trovata = False while parola_trovata == False: m = r.search(text, pos) if m == None: if totale == False: mex = "Finite le domande!\n" mex1 = "Hai totalizzato " + str(punti) + " punti! Complimenti!" mex50 = "Clicca [S]i o [N]o per chiudere il programma\n" print mex.center(70) print mex1.center(70) print mex50.center(70) risp = "----->[S]i / [N]o<-----" risposta = raw_input(risp.center(70)) break elif totale == True: print "Il punteggio massimo e' " + str(punti) + " punti!" break pos = m.end() dm = m.group(2) + '?' dom = dm.decode("UTF-8") dom = dom.center(80) domanda = '\n' + dom punteggio = int(m.group(3)) pat = True while pat == True: if totale == False: print domanda risp = "Cosa rispondi? [S]i o [N]o?" risposta = raw_input(risp.center(70)) for parol in yes: if parol in risposta: punti += punteggio mex2 = 'Ok, hai guadagnato %d punti' % punteggio mex5 = "Il tuo punteggio totale e' quindi di %d punti" % punti mex3 = "\n" + mex5.center(80) print mex2.center(70) print mex3.center(70) pat = False for parol in nein: if parol in risposta: mex4 = '\n' + 'Il tuo punteggio totale resta %d punti'.center(70) % punti print mex4.center(70) pat = False elif totale == True: punti += punteggio pat = False