在您的网址中使用导入时间

时间:2017-12-22 02:17:44

标签: python python-import

这是第一次尝试将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()

1 个答案:

答案 0 :(得分:2)

使用取代time的{​​{3}}模块。

就其本身而言,%M-%d-%Y毫无意义。它是一个应传递给模块的格式字符串,但您实际上并未将其定义为字符串,更不用说将其传递给time模块。

变化: %M-%d-%Y

要:

datetime.datetime.now().strftime('%m-%d-%Y')

注意: %M用于分钟,而非月份。您需要将其更改为小写“m”。