Skip to content

Commit 7953228

Browse files
committed
fix: correct minor typos in code
1 parent c01c402 commit 7953228

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

app/internal/world_clock.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime, timedelta
22
import json
3+
import logging
34
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
45

56
import dateutil.parser
@@ -175,10 +176,11 @@ def get_country(city_name: str) -> Optional[str]:
175176
Returns:
176177
str: The suitable country name.
177178
"""
178-
details = load_city_country_data_set()
179-
for city_element in details:
180-
if city_name.title() in city_element[CITY_NAME_KEY].title():
181-
return city_element[COUNTRY_NAME_KEY_IN_CITIES]
179+
data = load_city_country_data_set()
180+
details = data.get(city_name.title())
181+
if not details:
182+
return
183+
return details.get(COUNTRY_NAME_KEY_IN_CITIES)
182184

183185

184186
def get_subcountry(city_name: str) -> Optional[str]:
@@ -188,10 +190,11 @@ def get_subcountry(city_name: str) -> Optional[str]:
188190
Returns:
189191
str: The suitable subcountry name.
190192
"""
191-
details = load_city_country_data_set()
192-
for city_element in details:
193-
if city_name.title() in city_element[CITY_NAME_KEY].title():
194-
return city_element[SUBCOUNTRY_NAME_KEY_IN_CITIES]
193+
data = load_city_country_data_set()
194+
details = data.get(city_name.title())
195+
if not details:
196+
return
197+
return details.get(SUBCOUNTRY_NAME_KEY_IN_CITIES)
195198

196199

197200
async def get_api_data(url: str) -> Optional[List[Any]]:
@@ -205,8 +208,8 @@ async def get_api_data(url: str) -> Optional[List[Any]]:
205208
async with httpx.AsyncClient() as client:
206209
resp = await client.get(url)
207210
return resp.json()
208-
except (json.JSONDecodeError, httpx.HTTPError) as errh:
209-
print("Http Error:", errh)
211+
except (json.JSONDecodeError, httpx.HTTPError):
212+
logging.exception("Http Error")
210213

211214

212215
async def parse_timezones_list() -> List[Tuple[str, ...]]:
@@ -445,14 +448,9 @@ def get_part_of_day_and_feedback(time: datetime) -> Tuple[str, str]:
445448
tuple: The part of day description and the feedback.
446449
"""
447450
for part in PARTS_OF_THE_DAY_FEEDBACK:
448-
if (
449-
time
450-
>= datetime.strptime(
451-
part.start,
452-
"%H:%M:%S",
453-
)
454-
and time <= datetime.strptime(part.end, "%H:%M:%S")
455-
):
451+
start_time = datetime.strptime(part.start, "%H:%M:%S",)
452+
end_time = datetime.strptime(part.end, "%H:%M:%S")
453+
if (time >= start_time and time <= end_time):
456454
return part.time, part.desirability
457455

458456

app/resources/world-cities.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/test_world_clock.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def test_load_country_subcountry_data_set():
7979
('rio de janeiro', 'Brazil'),
8080
('pago pago', 'American Samoa'),
8181
('jerusalem', 'Israel'),
82-
('new york', 'United States'),
8382
('Narnia', None),
8483
]
8584

0 commit comments

Comments
 (0)