Fixed city search case-sensitive

Closes #2
This commit is contained in:
JuliusFreudenberger 2020-09-19 13:00:30 +02:00
parent bcdf9a81a3
commit e623b317c9

View file

@ -165,9 +165,9 @@ def get_city_by_name(city_name: str) -> City:
with open("city.list.json", "r") as city_list_file:
city_data = city_list_file.read()
city_json = json.loads(city_data)
city_list = list(filter(lambda x: x['name'] == city_name, city_json))
city_list = list(filter(lambda x: x['name'].casefold() == city_name.casefold(), city_json))
if len(city_list) == 0:
city_list = list(filter(lambda x: (x['name'].find(city_name)) != -1, city_json))
city_list = list(filter(lambda x: (x['name'].casefold().find(city_name.casefold())) != -1, city_json))
if len(city_list) == 0:
return City(cid=-1, name="none", lat=0, lon=0)
return City(cid=city_list[0]['id'], name=city_list[0]['name'], lat=city_list[0]['coord']['lat'],