Utente:BimBot/Scripts: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
nuovo script per totocalcio
Riga 2 164:
Il palinsesto è preso da [http://tv.lospettacolo.it/home.asp LoSpettacolo.it]. Ultimo aggiornamento: {{subst:#time:H:i, l j F Y|{{subst:LOCALTIMESTAMP}}}}.
</noinclude>
</pre>
 
== <tt>totocalcio.py</tt> ==
<source lang="python">
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wikipedia
import urllib2, re, time, codecs
 
def pageText(url):
request = urllib2.Request(url)
user_agent = 'BimBot/1.0'
request.add_header("User-Agent", user_agent)
response = urllib2.urlopen(request)
text = response.read()
response.close()
return text
def main():
args = wikipedia.handleArgs()
all = False
for currentArgument in args:
if currentArgument.startswith("-always"):
all = True
templateFile = codecs.open("modello_totocalcio.txt", "r", "utf-8")
modelloVoce = templateFile.read() # Legge il modello della pagina
templateFile.close()
urlo = "http://www.calcio.sisal.it/pages/totocalcio/ultimo.xwb"
wikipedia.output(u'Prendo la pagina dal server...')
try:
htmlText = pageText(urlo)
except urllib2.HTTPError:
try:
wikipedia.output(u"Errore del server. Aspetto 10 secondi... " + time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime()) )
time.sleep(10)
htmlText = pageText(urlo)
except urllib2.HTTPError:
wikipedia.output(u"Errore del server. Chiudo.")
return
concorso = re.search("<h2>Concorso n. (\d+) di (.*?) (\d+) (.*?) (\d+)</h2>", htmlText)
montepremi = re.search("<tr>\s*<th.*?>Il Montepremi</th>\s*</tr>\s*<tr>\s*<TD.*?>\s*Del Concorso \(premi a punteggio\)\s*</TD>\s*<TD>\s*EUR\s*</TD>\s*<TD>\s*(.*?)\s*</TD>\s*</tr>\s*<tr>\s*<TD.*?>\s*Riporto Jackpot conc\. precedente\s*</TD>\s*<TD>\s*EUR\s*</TD>\s*<TD.*?>\s*(.*?)\s*</TD>\s*</tr>\s*<tr\s*>\s*<TD.*?>\s*Montepremi totale del concorso\s*</TD>\s*<TD>\s*EUR\s*</TD>\s*<TD.*?>\s*(.*?)\s*</TD>\s*</tr>", htmlText)
montepremi9 = re.search("<tr>\s*<th.*?>Il Montepremi \"Il9\"</th>\s*</tr>\s*<tr>\s*<TD.*?>\s*Del Concorso \(premi a punteggio\)\s*</TD>\s*<TD>\s*EUR\s*</TD>\s*<TD>\s*(.*?)\s*</TD>\s*</tr>\s*<tr>\s*<TD.*?>\s*Riporto Jackpot conc\. precedente\s*</TD>\s*<TD>\s*EUR\s*</TD>\s*<TD.*?>\s*(.*?)\s*</TD>\s*</tr>\s*<tr>\s*<TD.*?>\s*Montepremi totale del concorso 9\s*</TD>\s*<TD>\s*EUR\s*</td>\s*<TD.*?>\s*(.*?)\s*</TD>\s*</tr>", htmlText)
bloccoQuote = "<tr>\s*<td>\s*(.*?)\s*</td>\s*<td>\"%s\"</td>\s*<td.*?>\s*(.*?)\s*</td>\s*</tr>"
bloccoPartita = "<tr>\s*<td.*?>\s*<b>\s*%s\s*</b>\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*<b>\s*(\d+) - (\d+)&nbsp;\s*</b>\s*</td>\s*<td.*?>\s*<b>\s*(\d+)&nbsp;\s*</b>\s*</td>\s*</tr>"
jackpotFuturi = re.search("<table.*?>\s*<tr>\s*<th.*?>\s*Jackpot prossimo concorso\s*</th>\s*</tr>\s*<tr>\s*<th.*?>.*?</th>\s*</tr>\s*<tr>\s*<td.*?><h2><b>14</b></h2></td>\s*<td.*?><h1>(.*?)<font.*?>.*?</font></h1></td>\s*</tr>\s*<tr>\s*<td.*?><h2><b>9</b></h2></td>\s*<td.*?><h1>(.*?)<font.*?>.*?</font></h1></td>\s*</tr>\s*</table>", htmlText)
page = wikipedia.Page(wikipedia.getSite(code='it', fam='wikinews'), "Italia: concorso n. " + concorso.group(1) + "/" + concorso.group(5) + " del Totocalcio")
if page.exists():
wikipedia.output("Nessuna nuova estrazione. Mi fermo.")
return
elencoSostituzioni = { # Sostituisce le variabili nel modello
'#super-id': concorso.group(1),
'#dow': concorso.group(2).replace('&igrave;', u'ì'),
'#giorno': concorso.group(3),
'#mese': concorso.group(4),
'#anno': concorso.group(5),
'#montepremi-parz': montepremi.group(1),
'#jackpot': montepremi.group(2),
'#montepremi-tot': montepremi.group(3),
'#futuro-jackpot': jackpotFuturi.group(1),
'#9-montepremi-parz': montepremi9.group(1),
'#9-jackpot': montepremi9.group(2),
'#9-montepremi-tot': montepremi9.group(3),
'#9-futuro-jackpot': jackpotFuturi.group(2),
}
partite = range(1, 15)
for p in partite:
match = re.search(bloccoPartita % p, htmlText, re.DOTALL)
elencoSostituzioni['#sq-' + str(p) + 'a'] = match.group(1).capitalize()
elencoSostituzioni['#sq-' + str(p) + 'b'] = match.group(2).capitalize()
elencoSostituzioni['#res-' + str(p) + 'a'] = match.group(3)
elencoSostituzioni['#res-' + str(p) + 'b'] = match.group(4)
elencoSostituzioni['#ok-' + str(p)] = match.group(5)
quotes = [9, 12, 13, 14]
for c in quotes:
match = re.search(bloccoQuote % c, htmlText)
elencoSostituzioni['#vincitori-' + str(c)] = match.group(1).replace('nessuna', '0')
elencoSostituzioni['#euro-' + str(c)] = match.group(2).replace('-', '0')
nuovoTesto = massiveReplace(elencoSostituzioni, modelloVoce)
#page = wikipedia.Page(wikipedia.getSite(code='it', fam='wikinews'), "Utente:BimBot/Sandbox") #DEBUG
wikipedia.output(">>>>> " + page.title() + " <<<<<")
wikipedia.showDiff('', nuovoTesto)
if not all:
choice = wikipedia.inputChoice(u"Modificare?", ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
else:
choice = 'y'
if choice in ['A', 'a']:
all = True
choice = 'y'
if choice in ['Y', 'y']:
page.put(nuovoTesto, u"Bot: Inserisco nuova estrazione del Totocalcio")
 
def massiveReplace(dict, text):
# Dato un testo ed un dizionario di sostituzioni, usa le regex per il "find and replace"
for k in dict:
text = re.sub(k, dict[k], text)
return text
 
if __name__ == "__main__":
try:
main()
finally:
wikipedia.stopme()
</source>
 
=== <tt>modello_totocalcio.txt</tt> ===
<pre>
{{data|#giorno #mese #anno|#dow}}
 
{| {{prettytable|align=center|text-align=center}}
|-
!colspan=6; style="background:#98A1B2;"|<span style="color:white">Totocalcio concorso n. #super-id di #dow #giorno #mese #anno</span>
|-
|width=20px;|1
|width=120px;|#sq-1a
|width=120px;|#sq-1b
|width=20px;|#res-1a
|width=20px;|#res-1b
!width=20px;|#ok-1
|-
|width=20px;|2
|width=120px;|#sq-2a
|width=120px;|#sq-2b
|width=20px;|#res-2a
|width=20px;|#res-2b
!width=20px;|#ok-2
|-
|width=20px;|3
|width=120px;|#sq-3a
|width=120px;|#sq-3b
|width=20px;|#res-3a
|width=20px;|#res-3b
!width=20px;|#ok-3
|-
|width=20px;|4
|width=120px;|#sq-4a
|width=120px;|#sq-4b
|width=20px;|#res-4a
|width=20px;|#res-4b
!width=20px;|#ok-4
|-
|width=20px;|5
|width=120px;|#sq-5a
|width=120px;|#sq-5b
|width=20px;|#res-5a
|width=20px;|#res-5b
!width=20px;|#ok-5
|-
|width=20px;|6
|width=120px;|#sq-6a
|width=120px;|#sq-6b
|width=20px;|#res-6a
|width=20px;|#res-6b
!width=20px;|#ok-6
|-
|width=20px;|7
|width=120px;|#sq-7a
|width=120px;|#sq-7b
|width=20px;|#res-7a
|width=20px;|#res-7b
!width=20px;|#ok-7
|-
|width=20px;|8
|width=120px;|#sq-8a
|width=120px;|#sq-8b
|width=20px;|#res-8a
|width=20px;|#res-8b
!width=20px;|#ok-8
|-
|width=20px;|9
|width=120px;|#sq-9a
|width=120px;|#sq-9b
|width=20px;|#res-9a
|width=20px;|#res-9b
!width=20px;|#ok-9
|-style="background:#D0FFD0;"
|width=20px;|10
|width=120px;|#sq-10a
|width=120px;|#sq-10b
|width=20px;|#res-10a
|width=20px;|#res-10b
!width=20px;|#ok-10
|-style="background:#D0FFD0;"
|width=20px;|11
|width=120px;|#sq-11a
|width=120px;|#sq-11b
|width=20px;|#res-11a
|width=20px;|#res-11b
!width=20px;|#ok-11
|-style="background:#D0FFD0;"
|width=20px;|12
|width=120px;|#sq-12a
|width=120px;|#sq-12b
|width=20px;|#res-12a
|width=20px;|#res-12b
!width=20px;|#ok-12
|-style="background:#D0FFD0;"
|width=20px;|13
|width=120px;|#sq-13a
|width=120px;|#sq-13b
|width=20px;|#res-13a
|width=20px;|#res-13b
!width=20px;|#ok-13
|-style="background:#D0FFD0;"
|width=20px;|14
|width=120px;|#sq-14a
|width=120px;|#sq-14b
|width=20px;|#res-14a
|width=20px;|#res-14b
!width=20px;|#ok-14
|-
|}
 
==Montepremi==
* Concorso n. #super-id: #montepremi-parz euro
* Jackpot (riporto concorso precedente): #jackpot euro
* Montepremi totale: '''#montepremi-tot''' euro
* Jackpot prossimo concorso: #futuro-jackpot euro
 
===Quote===
* n. 14: #euro-14 euro (#vincitori-14 vincitori)
* n. 13: #euro-13 euro (#vincitori-13 vincitori)
* n. 12: #euro-12 euro (#vincitori-12 vincitori)
 
==Montepremi "Il 9"==
* Concorso n. #super-id: #9-montepremi-parz euro
* Jackpot (riporto concorso precedente): #9-jackpot euro
* Montepremi totale: '''#9-montepremi-tot''' euro
* Jackpot prossimo concorso: #9-futuro-jackpot euro
 
===Quote===
* n. 9: #euro-9 euro (#vincitori-9 vincitori)
 
==Fonti==
{{fonte
|autore=
|url=http://www.calcio.sisal.it/pages/totocalcio/dettaglio_archivio.xwb?expandId=1373&CONCORSO=#super-id&ANNO=#anno
|titolo=Concorso n. #super-id di #dow #giorno #mese #anno
|agenzia=Sisal
|data=#giorno #mese #anno}}
 
{{pubblicato}}
 
[[Categoria:Europa]]
[[Categoria:Italia]]
[[Categoria:Giochi a premi]]
[[Categoria:Totocalcio]]
</pre>