In [1]:
import sys
import os
def get_url():
url = "https://www.jogossantacasa.pt/web/SCEstatisticas/euromilhoes"
import requests, re
a=re.compile("<li>([0-9]{1,2})</li><li>[0-9]+</li><li>[0-9,]+</li><li>[0-9]+/[0-9]{4}</li><li>[0-9]+/[0-9]+/[0-9]{4}</li><li>([0-9]{1,2})</li>")
r=requests.get(url)
al=a.findall(r.text)
numbers=[]
stars=[]
for a in range(50):
numbers.append(al[a][0]+" "+al[a][1])
for a in range(50,61):
stars.append(al[a][0]+" "+al[a][1])
return {'numbers': numbers,
'stars':stars}
def get_data(fich):
infile = open(fich, "r")
data = infile.readlines()
infile.close()
return data
def get_random_wheel(data, num):
population = []
for linha in data:
l=linha.strip().split()
population.extend([int(l[0])] * int(l[1]))
out = []
for k in range(num):
o = random.choice(population)
while o in out:
o = random.choice(population)
out.append(o)
out.sort()
return out
def get_chave(data):
num = get_random_wheel(data['numbers'], 5)
st = get_random_wheel(data['stars'], 2)
wks = 0;
for el in num:
wk = data['numbers'][el-1].strip().split()
wks+=int(int(wk[1]))
for el in st:
wk = data['stars'][el-1].strip().split()
wks+=int(int(wk[1]))
return {'numbers':sorted(num), 'stars':sorted(st), 'wks':wks}
In [2]:
data = get_url()
In [3]:
for a in range(10):
print get_chave(data)