私はこのAPIで行のダイナミックレンジを持っています。私はいくつかの以前のwhileループの使用を見てきましたが、このスクリプトのforループをwhileループのために交換する方法を見つけることはできません。whileループをwhileループのpythonに置き換える
header = ["fanduel", "fd_first_name", "fd_last_name", "fd_player_salary", "draftkings", "dk_first_name", "dk_last_name", "dk_player_salary"]
headers = {
"Authorization": "Basic " +
base64.b64encode('{}:{}'.format(USERNAME,PASSWORD)\
.encode('utf-8')).decode('ascii')
}
with open("dailydfs.csv", 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(header)
for fordate in range(20171215,20171216): #ENTER DATE'S
req = requests.get(url="https://api.mysportsfeeds.com/v1.1/pull/nhl/2017-2018-regular/daily_dfs.json?fordate=" + str(fordate) , headers=headers)
req.raise_for_status()
data = req.json()
daily_dfs = data['dailydfs']
fanduel = daily_dfs['dfsEntries'][0]['dfsType']
draftkings = daily_dfs['dfsEntries'][1]['dfsType']
for i in range(20):
fd_player = daily_dfs['dfsEntries'][0]['dfsRows'][i]['player']
salary_fd = daily_dfs['dfsEntries'][0]['dfsRows'][i]
fd_last_name = fd_player['LastName']
fd_first_name = fd_player['FirstName']
fd_player_salary = salary_fd['salary']
dk_player = daily_dfs['dfsEntries'][1]['dfsRows'][i]['player']
salary_dk = daily_dfs['dfsEntries'][1]['dfsRows'][i]
dk_last_name = dk_player['LastName']
dk_first_name = dk_player['FirstName']
dk_player_salary = salary_dk['salary']
writer.writerow([fanduel, fd_first_name, fd_last_name, fd_player_salary, draftkings, dk_first_name, dk_last_name, dk_player_salary])
print(fanduel, fd_first_name, fd_last_name, fd_player_salary, draftkings, dk_first_name, dk_last_name, dk_player_salary)
OUTPUT:daily_dfs['dfsEntries'][0]['dfsRows']
とdaily_dfs['dfsEntries'][1]['dfsRows']
の両方が同じ数の要素を持っているという仮定の下で
FanDuel Jonathan Quick 8800 DraftKings Martin Jones 8400
FanDuel Henrik Lundqvist 8600 DraftKings Aaron Dell 8300
FanDuel Frederik Andersen 8500 DraftKings Frederik Andersen 8200
FanDuel Martin Jones 8500 DraftKings Curtis McElhinney 8100
FanDuel Ben Bishop 8500 DraftKings Cory Schneider 7900
FanDuel Cory Schneider 8200 DraftKings Tyler Seguin 7800
お話はありますか? – CodeCollector
ある日、他の人よりも多くの「選手」が遊んでいます。私がforループに置いておくと、どれくらいの数が存在しているかを確認し、毎日 'range()'を変更する必要があります。スクリプトのポイントは、プロセスを自動化することです。 –