Sorteador de chaves do Euromilhões

Baseado numa roullete wheel em que a fitness dos números é dado pelo número de sorteios em que o número não aparece.


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)


{'wks': 134, 'numbers': [9, 11, 14, 24, 46], 'stars': [9, 11]}
{'wks': 122, 'numbers': [7, 11, 14, 23, 29], 'stars': [3, 9]}
{'wks': 86, 'numbers': [9, 20, 29, 35, 47], 'stars': [5, 10]}
{'wks': 109, 'numbers': [1, 9, 24, 36, 50], 'stars': [4, 11]}
{'wks': 81, 'numbers': [9, 30, 33, 36, 46], 'stars': [4, 11]}
{'wks': 138, 'numbers': [7, 9, 14, 16, 39], 'stars': [3, 10]}
{'wks': 86, 'numbers': [2, 7, 16, 20, 49], 'stars': [3, 10]}
{'wks': 103, 'numbers': [7, 14, 15, 47, 48], 'stars': [6, 11]}
{'wks': 104, 'numbers': [1, 7, 24, 45, 46], 'stars': [9, 11]}
{'wks': 93, 'numbers': [9, 11, 16, 23, 43], 'stars': [10, 11]}