parent
bcdf9a81a3
commit
e623b317c9
1 changed files with 2 additions and 2 deletions
|
@ -165,9 +165,9 @@ def get_city_by_name(city_name: str) -> City:
|
||||||
with open("city.list.json", "r") as city_list_file:
|
with open("city.list.json", "r") as city_list_file:
|
||||||
city_data = city_list_file.read()
|
city_data = city_list_file.read()
|
||||||
city_json = json.loads(city_data)
|
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:
|
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:
|
if len(city_list) == 0:
|
||||||
return City(cid=-1, name="none", lat=0, lon=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'],
|
return City(cid=city_list[0]['id'], name=city_list[0]['name'], lat=city_list[0]['coord']['lat'],
|
||||||
|
|
Loading…
Reference in a new issue