这是第一次尝试将import time
与python脚本一起使用。在URL
内我试图用动态日期替换静态日期。 URL
中的日期采用此格式12-21-2017
。这可能是import time
吗?
import csv
import requests
import time
outfile = open("Labs_StartingGoalies.csv","w",newline='')
writer = csv.writer(outfile)
writer.writerow(["HomeTeam","HomeGoalie","HomeGoalieStatus","DK","FD","VisitorTeam","VisitorGoalie","VisitorGoalieStatus","DK","FD"])
req = requests.get('https://www.fantasylabs.com/api/lines/4/' + %M-%d-%Y + '/startinggoalies')
data = req.json()['GoalieMatchups']
for teams in data:
HomeTeam = teams['Properties']['HomeTeam']
HomeGoalie = teams['Properties']['HomeGoalie']
HomeGoalieStatus = teams['Properties']['HomeGoalieStatus']
HomeGoalieSalary_DK = teams['Properties']['HomeGoalieSalary_DK']
HomeGoalieSalary_FD = teams['Properties']['HomeGoalieSalary_FD']
VisitorTeam = teams['Properties']['VisitorTeam']
VisitorGoalie = teams['Properties']['VisitorGoalie']
VisitorGoalieStatus = teams['Properties']['VisitorGoalieStatus']
VisitorGoalieSalary_DK = teams['Properties']['VisitorGoalieSalary_DK']
VisitorGoalieSalary_FD = teams['Properties']['VisitorGoalieSalary_FD']
writer.writerow([HomeTeam,HomeGoalie,HomeGoalieStatus,HomeGoalieSalary_DK,HomeGoalieSalary_FD,VisitorTeam,VisitorGoalie,VisitorGoalieStatus,VisitorGoalieSalary_DK,VisitorGoalieSalary_FD])
outfile.close()
答案 0 :(得分:2)
使用取代time
的{{3}}模块。
就其本身而言,%M-%d-%Y
毫无意义。它是一个应传递给模块的格式字符串,但您实际上并未将其定义为字符串,更不用说将其传递给time
模块。
变化:
%M-%d-%Y
要:
datetime.datetime.now().strftime('%m-%d-%Y')
注意:
%M
用于分钟,而非月份。您需要将其更改为小写“m”。