import requests

GET = "https://pydefis.callicode.fr/defis/CriPiafabec/get/Cavogrenier/b3489"
POST = "https://pydefis.callicode.fr/defis/CriPiafabec/post/Cavogrenier/b3489"


res = requests.get(GET)
contents = res.text.splitlines()

print(res.text)
print("***")

sig = contents[0]
input = contents[1:]

d = 1000

print("*",input,"*")
############################################
d = d / 200

for i in range(len(input)):
    input[i] = [int(input[i][j].replace(".", "0").replace("@", "-100")) for j in range(len(input[i]))]

for y in range(len(input)):
    for x in range(len(input[y])):
        if input[y][x]>=0:
            #Il n'y a pas de piafabec
            continue
        for y2 in range(len(input)):
            for x2 in range(len(input[y])):
                if input[y2][x2]<0:
                    #Il y a déjà un piafabec, on passe
                    continue
                if (x-x2)**2+(y-y2)**2 <= d**2:
                    input[y2][x2] += 1

for i, line in enumerate(input):
    print(i, line)
print("")

max_piaf = 0
for i in range(len(input)):
    max_piaf = max(max_piaf, max(input[i]))
print(max_piaf, "piafabec à portée")
print("")

solution = list()
for y in range(len(input)):
    for x in range(len(input[y])):
        if input[y][x] == max_piaf:
            solution.append("[{}, {}]".format(y,x))

solution = ", ".join(solution)

print(solution)

param = {'sig':sig, 'rep':solution}
res = requests.post(POST, verify=False, data=param)

print(res)
print(res.text)
