zagortenay333 / conky_themes

A small collection of conky configs
624 stars 93 forks source link

Can't get forecast with free OpenWeatherMap account #47

Closed eliasdaler closed 6 years ago

eliasdaler commented 6 years ago

Right now, it's not possible to call api.openweathermap.org/data/2.5/forecast/daily with a free OpenWeatherMap account. However, it's possible to get forecast via api.openweathermap.org/data/2.5/forecast?...cnt=4 and get all the data from it.

I'd submit a PR, but I only made changes to one theme, and I don't know how to change this in all themes, I suppose you've generated them all by script?

eliasdaler commented 6 years ago

Apparently, this request returns a data for each 3 hours of each day. The problem is that it doesn't return today's "00:00" as the first element, it returns the closest data to current time, so there'll be need to check date and then get minimum/maximum for each day. Pretty complex.

zagortenay333 commented 6 years ago

They updated their api. See this pull request for the change if you are interested in making a pull: https://github.com/zagortenay333/conky-Vision/pull/15/files

Else, I'll update it in the next few days.

eliasdaler commented 6 years ago

Are you sure that it's a correct fix? If you look at what "api.openweathermap.org/data/2.5/forecast" returns, you'll see that [1], [2], [3] doesn't mean "tomorrow", "a day after tomorrow", etc. To get correct information, we need to get minimum for each day somehow.

But it's not as simple as getting min of list[4:8] or something like that, because it depends on user's time, as far as I can tell. Sometimes [0] is today's 00:00, sometimes it's 09:00.

zagortenay333 commented 6 years ago

Oh, I see...

God, the openweathermap api site is one giant clusterfu**. Why do they display the forecast/daily? link on the 5 day forecast site if it's not available to free users?

Also, how am I able to obtain the daily forecast even though I am not a paying user...?

eliasdaler commented 6 years ago

Ha-ha, yeah, they suddenly changed it and broke other repos... which is how I found out how to fix it. My guess is that this doesn't affect all keys... maybe only the once made after some date, I don't know.

zagortenay333 commented 6 years ago

Well we just get the first element for today's forecast, and every 00:00 element for the other days. That seems like the only thing that makes sense.

eliasdaler commented 6 years ago

But to get min/max temperature for a day, you'll need to look at 8 elements for each day, actually.

zagortenay333 commented 6 years ago

Ah yeah, it's only for the 3 hours... Well then we'll loop over the elements. Btw, does every other day start at 00:00 always?

What a weird api. The free account gets a detailed 3 hours forecast, the paid account gets a daily forecast. Not sure how that makes sense..

eliasdaler commented 6 years ago

Yes, they always start with 00:00, it's just the current day that needs to be checked.

Yeah, that's really weird. They said that they limit amount of days the free account can get, but still...

zagortenay333 commented 6 years ago

This should work now. Let me know whether it works correctly.

eliasdaler commented 6 years ago

Thank you, it works well! (Though I needed to manually launch weather script, because for some reason it wasn't executed if there wasn't weather.json and forecast.json already created)

zagortenay333 commented 6 years ago

What weather script?

eliasdaler commented 6 years ago

This one

For some reason Conky said that it couldn't find icons in .cache folder which are supposed to be copied

I'll try to reinstall the theme from scratch and tell you exactly the problems I had.

zagortenay333 commented 6 years ago

Yeah, you might need to run conky once and then restart it. It's some race condition at the start, and I can't be bothered with it tbh.

pabugeater commented 5 years ago

eliasdaler said:

Yes, they always start with 00:00, it's just the current day that needs to be checked.

Correct. If you want the forecast low/high for Today you only get a chance to inspect all 8 3-hour results if you make a forecast call between 00:00 and 01:00 in the morning. But, if you keep tabs of all the future low/high temps, within the next 24 hours you will have all 8 results for the next and subsequent days. In my case, the daily 3-hourly times are 01:00, 04:00, 07:00, 10:00, 13:00, 16:00, 19:00 and 22:00.

I persist the data in client-side localStorage as a hash with keys epoch times and values the forecast temperature. I keep forecast temperatures two days into the future and remove hash entries that are two days past. It would be nice to have something more persistent than localStorage, but it's good enough for my purposes.

http://www.bigcatos.com/Software/getLowHighTemperatureOWM.js