Issue
This is my code.
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)
What I want to do is to run it on some regular intervals. However, I am getting an error saying "weather_api() missing 1 required positional argument: 'URL'"
. I've tried to pass it into the schedule schedule.every(10).minutes.do(weather_api(URL))
but then I am getting the first argument must be callable
error. Also in this case...
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)
...the error remains. I have tried to use Advanced Python Scheduler before but the problem was same. My script works fine otherwise. What am I doing wrong?
Solution
See the source code of schedule
You may want to use schedule.every(10).minutes.do(weather_api, URL)
Answered By - lincr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.