import json import requests import mysql.connector mydb = mysql.connector.connect( host='localhost', user = 'dawid', password = '1qazXSW@', database = 'pokemony' ) mycursor = mydb.cursor() sql = "INSERT INTO pokemon (id, name, exp) VALUES (%s, %s, %s)" mydb.commit() p_list = 'https://pokeapi.co/api/v2/pokemon/' p_data = [] x=1 def strongest(f_p_request,f_data): p_data.append([f_p_request['name'], f_p_request[f_data]]) #for i in range(10): while True: print(x) p_request=requests.get(p_list+str(x)) if (p_request.status_code!=200): break strongest(p_request.json(),'base_experience') mycursor.execute(sql, (x,p_data[x-1][0],p_data[x-1][1])) mydb.commit() x+=1 p_data.sort(key=lambda x: (x[1] is not None, x[1]),reverse=True) print ('\nliczba pokemonów = '+str(x-1)) print ('\nnajsilniejsze pokemony:\n') for i in range(5): print(p_data[i][0],'Sila=',p_data[i][1])