Purple exclamation mark.svg 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.

Red exclamation mark.svg 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

From Botwiki
Jump to: navigation, search
Spiegazioni al Bar di Wikipedia
#!/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 wikipedia
import re
from wikipedia import getSite
from wikipedia import Page
 
totale = False
 
for arg in wikipedia.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']
page = 'Wikipedia:Scherzi_e_STUBidaggini/Wikidipendenza'
p = Page(getSite(), page)
text = p.get()
regexp = '\#( |_|)(.*?)\? \(([0-9]|[0-9][0-9])\)'
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!"
                        mex1 = "Hai totalizzato " + str(punti) + " punti! Complimenti!"
                        print mex.center(70)
                        print mex1.center(70)
                        break
                elif totale == True:
                        print "Il punteggio massimo e' " + str(punti) + " punti!"
                        break
	pos = m.end()
	dom = m.group(2) + '?'
	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 = wikipedia.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
Personal tools
Share