Compare commits
5 Commits
357baf0b57
...
02782a6ce3
Author | SHA1 | Date | |
---|---|---|---|
|
02782a6ce3 | ||
|
69c0703e17 | ||
|
f1ce9fb455 | ||
|
20a153e857 | ||
|
55fdfc2c8d |
@ -13,31 +13,38 @@ base_url = "https://api.openweathermap.org/data/2.5/weather?"
|
|||||||
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
|
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
|
||||||
response = requests.get(complete_url)
|
response = requests.get(complete_url)
|
||||||
|
|
||||||
x = response.json()
|
data = response.json()
|
||||||
|
|
||||||
if x["cod"] != "404":
|
print()
|
||||||
|
match response.status_code:
|
||||||
|
case 200:
|
||||||
|
info_main = data["main"]
|
||||||
|
info_weather = data["weather"]
|
||||||
|
current_temperature = info_main["temp"]
|
||||||
|
current_pressure = info_main["pressure"]
|
||||||
|
current_humidity = info_main["humidity"]
|
||||||
|
weather_description = info_weather[0]["description"]
|
||||||
|
|
||||||
y = x["main"]
|
print(Columns([
|
||||||
current_temperature = y["temp"]
|
Panel(f"[blue]{round(current_temperature - 273.15, 2)}°C",
|
||||||
current_pressure = y["pressure"]
|
title="[bold]Temperature"),
|
||||||
current_humidity = y["humidity"]
|
|
||||||
z = x["weather"]
|
|
||||||
weather_description = z[0]["description"]
|
|
||||||
|
|
||||||
print()
|
Panel(f"[blue]{current_pressure}hPa",
|
||||||
print(Columns([
|
title="[bold]Atmospheric Pressure"),
|
||||||
Panel(f"[blue]{round(current_temperature - 273.15, 2)}°C",
|
|
||||||
title="[bold]Temperature[/bold]"),
|
|
||||||
|
|
||||||
Panel(f"[blue]{current_pressure}hPa",
|
Panel(f"[blue]{current_humidity}%",
|
||||||
title="[bold]Atmospheric Pressure[/bold]"),
|
title="[bold]Humidity"),
|
||||||
|
|
||||||
Panel(f"[blue]{current_humidity}%",
|
Panel(f"[blue]{weather_description}",
|
||||||
title="[bold]Humidity[/bold]"),
|
title="[bold]Description"),
|
||||||
|
]))
|
||||||
|
|
||||||
Panel(f"[blue]{weather_description}",
|
case _:
|
||||||
title="[bold]Description[/bold]"),
|
if "message" in data:
|
||||||
]))
|
print(Panel(data["message"],
|
||||||
|
title=f"[bold red]Error: {response.status_code}",
|
||||||
else:
|
expand=False))
|
||||||
print(" City Not Found ")
|
else:
|
||||||
|
print(Panel("unknown error",
|
||||||
|
title=f"[bold red]Error: {response.status_code}",
|
||||||
|
expand=False))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user