Closed Berserkir-Wolf closed 3 years ago
Is there a way to remove this requirement?
Sure, use .get()
for each of the parts and refactor the string generation to assemble only the relevant pieces.
I'll take a look :) I tried testing with some random international locations, but clearly not Gisborne, New Zealand
NZ is probably a little further out of the way than most places running a sopel instance 🤣 At some point I'll get back into module work. I've not worked on a stock module for a while, got a little spoiled by the spicebot project.
Looking at the response in Powershell I get the below:
place_id : 199999
licence : https://locationiq.com/attribution
osm_type : node
osm_id : 60269696
boundingbox : {-38.821326, -38.501326, 177.8606487, 178.1806487}
lat : -38.661326
lon : 178.0206487
display_name : Gisborne, 4010, New Zealand
class : place
type : city
importance : 0.7593094441583
icon : https://locationiq.org/static/images/mapicons/poi_place_city.p.20.png
address : @{city=Gisborne; region=Gisborne; postcode=4010; country=New Zealand; country_code=nz}
Lat, Long, and Address are all there - but no state or county. As a comparison to a US location:
Gisborne:
address : @{city=Gisborne; region=Gisborne; postcode=4010; country=New Zealand; country_code=nz}
Boston:
address : @{city=Boston; county=Suffolk County; state=Massachusetts; postcode=02203; country=United States of America; country_code=us}
Maybe a clause for 'if $r.keys contains city and not $r.keys contains state then format = city, region, country' or similar?
Right, after some further testing... Replacing
if 'city' in address.keys():
with
if 'region' in address.keys():
location = '{}, {}, {}'.format(address['city'],
address['region'],
address['country_code'].upper())
elif 'city' in address.keys():
allows querying directly (.weather Gisborne, NZ
) but fails to setlocation with
Unexpected error (Unable to geocode) from dysonparkes at 2020-12-10 21:55:57.066577. Message was: .weather setlocation Gisborne, NZ
I am able to get weather by just giving a single city (Gisborne), but cannot set the location. It's a little strange.
Running a sopel docker instance, and installed the weather module a while ago. For locations without a 'state' attached, lookup fails with the below:
If I look at the LocationIQ API directly, there's no "state" attribute being passed, and there is definitely a response from LocationIQ for the location being looked up (Gisborne, New Zealand).
If I query OpenWeatherMap directly using the API key sopel is using, then I get results with a query of "gisborne, nz". Query:
http://api.openweathermap.org/data/2.5/weather?q=Gisborne,nz&APPID={APIKEY}&units=metric
Result:None of the responses have a 'state' key, which is as expected. Not all countries use a 'State' system. Line 150 of the module seems to expect/require an entry for state or it fails to resolve. Is there a way to remove this requirement?