【发布时间】:2019-03-04 04:47:09
【问题描述】:
这是我的代码。
from API.helpers import get_weather_data, json_to_df, create_dict
import schedule, time
URL = 'https://pm1aapplicantsdata.blob.core.windows.net/databases/CitiesWeather/CitiesWeather.csv'
columns = ["name","sys.country","main.temp",
"main.humidity","main.pressure",
"visibility", "wind.speed"]
def weather_api(URL):
dict = create_dict(URL)
for city, code in dict.items():
data = get_weather_data(city, code)
json_to_df(data, columns)
schedule.every(10).minutes.do(weather_api())
while True:
schedule.run_pending()
time.sleep(1)
我想做的是定期运行它。但是,我收到一条错误消息"weather_api() missing 1 required positional argument: 'URL'"。我试图将它传递到时间表schedule.every(10).minutes.do(weather_api(URL)),但后来我收到the first argument must be callable 错误。同样在这种情况下...
def weather_api():
URL = 'https://pm1aapplicantsdata.blob.core.windows.net/databases/CitiesWeather/CitiesWeather.csv'
dict = create_dict(URL)
for city, code in dict.items():
data = get_weather_data(city, code)
json_to_df(data, columns)
schedule.every(10).minutes.do(weather_api())
while True:
schedule.run_pending()
time.sleep(1)
...错误仍然存在。我之前尝试过使用 Advanced Python Scheduler,但问题是一样的。否则我的脚本工作正常。我做错了什么?
【问题讨论】:
标签: python python-3.x scheduled-tasks schedule