Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman-Sokolov-V committed Dec 27, 2024
1 parent 45c69a4 commit 299cc87
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

load_dotenv()


def get_weather() -> None:
api_key = os.getenv("API_KEY")
city = os.getenv("CITY")
Expand All @@ -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__":
Expand All @@ -34,5 +37,3 @@ def get_weather() -> None:
print(weather)
except Exception as e:
print(f"Error: {e}")


0 comments on commit 299cc87

Please sign in to comment.