From 299cc87bbedd305b7e9fb4bc1cadb9401b30459e Mon Sep 17 00:00:00 2001 From: Roman Sokolov <gnonasis@gmail.com> Date: Fri, 27 Dec 2024 16:33:34 +0200 Subject: [PATCH] Solution --- app/main.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/main.py b/app/main.py index 008efac8..ee7fdc34 100644 --- a/app/main.py +++ b/app/main.py @@ -4,6 +4,7 @@ load_dotenv() + def get_weather() -> None: api_key = os.getenv("API_KEY") city = os.getenv("CITY") @@ -16,15 +17,17 @@ def get_weather() -> None: response = requests.get(URL + f"key={api_key}&q={city}") if response.status_code == 200: return ( - f"{response.json()["location"]["name"]}/" - f"{response.json()["location"]["country"]} " - f"{response.json()["location"]["localtime"]} " - f"Weather: {response.json()["current"]["temp_c"]} Celsius, " - f"{response.json()["current"]["condition"]["text"]}" + f"{response.json()['location']['name']}/" + f"{response.json()['location']['country']} " + f"{response.json()['location']['localtime']} " + f"Weather: {response.json()['current']['temp_c']} Celsius, " + f"{response.json()['current']['condition']['text']}" ) else: raise Exception( - f"Error fetching weather data: {response.status_code}, {response.text}") + f"Error fetching weather data: " + f" {response.status_code}, {response.text}" + ) if __name__ == "__main__": @@ -34,5 +37,3 @@ def get_weather() -> None: print(weather) except Exception as e: print(f"Error: {e}") - -