Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weather@mockturtl: Link to openweathermap.org brings up wrong city #3916

Closed
jkirk opened this issue Aug 30, 2021 · 6 comments · Fixed by #4103
Closed

weather@mockturtl: Link to openweathermap.org brings up wrong city #3916

jkirk opened this issue Aug 30, 2021 · 6 comments · Fixed by #4103

Comments

@jkirk
Copy link
Contributor

jkirk commented Aug 30, 2021

 * Applet version/Build date: Version 3.0.10 (2021-06-21 21:55:55)
 * Cinnamon version:  Cinnamon 4.8.6
 * Distribution: Debian/GNU Linux 11 (bullseye)
 * Graphics hardware *and* driver used

Notify author of applet: @mockturtl

Issue

After opening the applet and when clicking on the location at the top of the applet, the following URL is opened:
https://openweathermap.org/city/ which defaults to London, GB (or whatever city was opened last).

It would be nice if the given location/city is opened.

Steps to reproduce

Open the weather applet. Click on the location on the top. London, GB in https://openweathermap.org/city/ is opened.

Expected behaviour

https://openweathermap.org/city/ with the given location/city should open.

Other information

Thank very much for this cool applet!

@Gr3q
Copy link
Contributor

Gr3q commented Sep 10, 2021

Unfortunately I only get lat/long back from openweathermap, they don't return the nearest town's ID which I can use to open the correct URL, so I rely on you (the user) to permit the website to use your location, so it displays the correct one.

Alternatively I could open the map, but that is not really useful

@jkirk
Copy link
Contributor Author

jkirk commented Sep 10, 2021

I just found this in https://openweathermap.org/api/hourly-forecast#cityid5:

List of city ID city.list.json.gz can be downloaded here http://bulk.openweathermap.org/sample/

There city.list.json.gz seems to contain all city IDs. Does this help?

I.e. with this I was able to to open Botarell, ES -> city ID: 6361276 -> https://openweathermap.org/city/6361276

@Gr3q
Copy link
Contributor

Gr3q commented Sep 13, 2021

It's useful that the information is available, but note that file is 40Mb!

To use it first I need to load it in memory, which would take the same amount of space just for a weather applet. Secondly, I either make you download it through updates (again 40Mb bigger update if they let me) or make you download it once at runtime.

Both of the cases I will have to order the list by lat then long once (which would take quite a long) then use it to search.

I can implement a proof of concept to show the performance and memory impact it would have if you like. For now, I messaged OpenWeatherMap about including the ID in their API output.

@jkirk
Copy link
Contributor Author

jkirk commented Dec 9, 2021

Any update on this? Did OpenWeatherMap answer your request? Maybe we/one could build a mini API which returns the city ID with the given city...

I played around with the OpenWeatherMap search and came up with:

❯ curl 'https://openweathermap.org/data/2.5/find?q=Botarell,%20ES&appid=439d4b804bc8187953eb36d2a8c26a02&units=metric'
{"message":"accurate","cod":"200","count":2,"list":[{"id":6361276,"name":"Botarell","coord":{"lat":41.1538,"lon":1.0067},"main":{"temp":284.35,"feels_like":283.56,"temp_min":279.51,"temp_max":285.18,"pressure":1013,"humidity":78},"dt":1639084419,"wind":{"speed":2.24,"deg":250},"sys":{"country":"ES"},"rain":null,"snow":null,"clouds":{"all":40},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}]},{"id":3127762,"name":"Botarell","coord":{"lat":41.1363,"lon":0.9892},"main":{"temp":284.59,"feels_like":283.83,"temp_min":279.61,"temp_max":285.27,"pressure":1013,"humidity":78},"dt":1639084338,"wind":{"speed":2.24,"deg":250},"sys":{"country":"ES"},"rain":null,"snow":null,"clouds":{"all":40},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}]}]}

So, unfortunately there are two results for Botarell, ES (haven't checked why), but I opt for the first one and so this is my quick n' dirty hack to retrieve the city id:

❯ curl 'https://openweathermap.org/data/2.5/find?q=Botarell,%20ES&appid=439d4b804bc8187953eb36d2a8c26a02&units=metric' -s | jq ".list[0].id"
6361276

(The URL (with the appid) was taken from the Firefox Developer Tools, where I copied the request as cURL).

@Gr3q
Copy link
Contributor

Gr3q commented Dec 12, 2021

I sent them an email, they just replied with boilerplate, then I sent a reply and they never got back to me so I forgot about it.

They return the ID via the current weather call https://openweathermap.org/current#geo what I used to use, but it's still an extra network request I don't really want to make.

Anyway, probably I will add it back in just for the ID with some kind of caching.

Edit: This will get you the closest one it can find, but it might not match the city/country displayed in the applet because I don't get those from OpenWeatherMap either

@jkirk
Copy link
Contributor Author

jkirk commented Dec 20, 2021

Works like a charm! Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants