Closed project-owner closed 3 years ago
Hello @project-owner please take a look here: https://github.com/csparpa/pyowm/issues/309 you basically should specify the 2 letter name of the US country for your city instead of using a generic 'US'. In your example, if you look for 'New York' belonging to the the New York state, you must use use country='NY' instead of 'US'. please tell me if this works ok! thanks
It works, thank you! But how it will distinguish cities in California (CA) from the cities in Canada (CA)? I've tried to search on OpenWeather site: https://openweathermap.org/find and it works fine for query 'New York, US' and for 'New York, NY, US' but doesn't work for 'New York, NY'. Don't you use the same API for search? Thanks!
PyOWM uses OpenWeatherMap's API which might or might not be used also by the webpage you've found on their website I can't check this out right now but IMO when you hit enter on their searchbar, queries are run directly against their databases - this would explain why the page behaves differently from the API
As regards the Canadian Vs California issue... Well, good one! I think this is something OpenWeatherMap's guys should answer!!
Can you find a city in California and one in Canada having the exactly same name? If so, please give it a whirl and see what results you get :)
Thanks
Claudio Sparpaglione @.*** http://linkedin.com/in/claudiosparpaglione
On Sun, May 16, 2021, 17:14 project-owner @.***> wrote:
It works, thank you! But how it will distinguish cities in California (CA) from the cities in Canada (CA)? I've tried to search on OpenWeather site: https://openweathermap.org/find and it works fine for query 'New York, US' and for 'New York, NY, US' but doesn't work for 'New York, NY'. Don't you use the same API for search? Thanks!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/csparpa/pyowm/issues/376#issuecomment-841830938, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHOXXWX4CUGCD2ZFUMZIOTTN7ONBANCNFSM446GJIQQ .
There are some of them (https://en.wikipedia.org/wiki/List_of_U.S._places_named_after_non-U.S._places): Ontario Galt Inglewood probably more. Also there are 50 states in US and some of them can coincide with another country codes. For example Delaware has the same code as Germany - DE. Is there OpenWeather forum where I can ask this question?
Yahoo Weather is using both parameters: state + country. I'm not sure if it's possible somehow here.
Thanks!
This is their support center URL: https://openweathermap.force.com/s/contactsupport
Anyway, just for you to know: when you call the locations_for function on the cityIDregistry object, pyOWM performs a local query against text files that were bundled from OpenWeatherMap at release time. If you take a look at those files, they tell "state" from "country" when country=US That's the best we can do with the info OpenWeatherMap provides.
The mismatch between Californian and Canadian names could happen when you try to query e.g. the actual weather on them via pyOWM - which will invoke the remote OpenWeatherMap API. This is the case that needs to be investigated
Thanks, pls keep me posted
I'm not sure which file you use to look up the city info. I've had a look to this one: city.list.json.gz which I found here: https://bulk.openweathermap.org/sample/
Here is the example for the city Ontario in Canada and California:
{
"id": 5379439,
"name": "Ontario",
"state": "CA",
"country": "US",
"coord": {
"lon": -117.650887,
"lat": 34.063339
}
}
{
"id": 6093943,
"name": "Ontario",
"state": "",
"country": "CA",
"coord": {
"lon": -84.499832,
"lat": 49.250141
}
}
It would be possible to avoid ambiguity if you would query first by country and then by state. I use the one call API so I get longitude/latitude from the city info and provide in that API, so I don't call any other API with city/country info. It's only for lookup.
I believe the correct API would be:
city_registry.locations_for("Ontario", country="CA")
city_registry.locations_for("Ontario", country="US", state="CA")
where 'state' is optional.
Thanks!
I also cannot get the info for Washington:
city_registry.locations_for("Washington", country="DC")
returns empty list.
Thanks @project-owner for notifying.
Yes, the API you propose is the way to go and would be a breaking change with respect to today's usage of the country
field
I'd like to implement it - and maybe take the chance to innovate the way PyOWM stores city IDs internally (4 separate bz2 compressed files - here)
I was thinking about shipping only 1 sqlite db file which can be natively queried from Python, but that should need to come with an acceptable size - ideally less than 10 MBs
I'm migrating from the Yahoo Weather API which will reach end-of-life by June 1st. I hope to replace it by that time. If your new API won't be ready I will ask users to provide latitude/longitude instead of city name and country.
You could create new function for example either 'locations_for_2' or 'locations_for_city' to avoid the breaking change in the API. Thanks!
@project-owner Hello, just to let you know that the refactoring is in the works (https://github.com/csparpa/pyowm/commit/783cb8beeddfa0e3cf2bfce2c768e583e692901d) and will be shipped on the next release!
Good news. I hope it will be able to coexist with my app which is also using SQLite.
Hi, I'm trying to use the following function to get the city info:
It returns the empty list. The following function returns non-empty list:
What could be the reason for the empty list in the first case? I tried many different US cities and all of them return empty list. Thanks!