A way to reload forecast in lazy mode with out the double call overhead
Closed this issue · 3 comments
I am currently using load_forecast() with lazy loading because I'm interested in only data from currently and want to minimize data transferred. When I load_forecast() it takes one API call. When I call get_currently() it takes another. If I wanted to get fresh data I would need to call load_forecast() again. This again takes another API call.
It would be nice if load_forecast() didn't take up an API call on subsequent requests. Or, a way to clear the data so the next call to get_currently() lazily fetched new data.
I am actually thinking of making a few changes over the next few weeks, adding an update() method will be on the list.
In the mean time you can avoid the API call from load_forecast() by removing the "currently" key from the json dictionary. If the "currently" key is missing, it will load it again when called.
Give this a go.
f = Forecastio("Your API Key")
f.load_forecast(-31.967819, 115.87718, lazy=True)
f.getCurrently().time
#Displays the time of the last forecast
f.json.pop("currently")
#Removes the "currently" key from the json dictionary
f.getCurrently().time
#reloads the forecast with a different time
I had tried something similar but it didn't work. Your suggestion does. Thanks for the great library!
I have made some big changes and there is now an update() method. Let me know what you think.