Skip to content

Commit

Permalink
solution1
Browse files Browse the repository at this point in the history
  • Loading branch information
Olevsky-Ivan committed Dec 11, 2024
1 parent b6907d4 commit a10ba4d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
API_KEY = os.getenv("API_KEY")
city = "Paris"


def get_weather() -> None:
url = (
f"http:"
f"//api.weatherapi.com/v1/current.json?key={API_KEY}"
f"&q={city}&aqi=no"
)
response = requests.get(url)

if response.status_code == 200:
url = f"http://api.weatherapi.com/v1/current.json?key={API_KEY}&q={city}&aqi=no"
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
print(f"Weather in {city}: {data['current']['temp_c']}°C")

except requests.exceptions.RequestException as e:
print(f"Error fetching weather data: {e}")
except KeyError:
print("Unexpected response format.")

if __name__ == "__main__":
get_weather()

0 comments on commit a10ba4d

Please sign in to comment.