尝试每天运行并使用摆锤另存为单独的 CSV 文件。现在我只能拿到第一天的period
。不确定我是否需要outfile
,但我假设我需要,因为我希望每个单独的 CSV 文件都写入、关闭并开始一个新文件。
import csv
import requests
import datetime
import pendulum
start = pendulum.datetime(2018, 1, 1)
end = pendulum.today()
period = pendulum.period(start, end)
for dt in period.range('days'):
dt.format('YYYY-MM-DD')
break
the_date = dt.format('YYYY-MM-DD')
outfile = open('TEST_PENDULUM_' + str(the_date) + '.csv',"w",newline='')
writer = csv.writer(outfile)
writer.writerow(["Date"])
req = requests.get('https://www.fantasylabs.com/api/lines/4/' + str(the_date) + '/startinggoalies')
data = req.json()['GoalieMatchups']
for teams in data:
HomeTeam = teams['Properties']['EventDate']
print(HomeTeam)
writer.writerow([HomeTeam])
outfile.close()