Overhaul error handling
This commit is contained in:
parent
20a153e857
commit
f1ce9fb455
@ -15,30 +15,31 @@ response = requests.get(complete_url)
|
|||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
if response.status_code == 200:
|
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"]
|
||||||
|
|
||||||
info_main = data["main"]
|
print(Columns([
|
||||||
info_weather = data["weather"]
|
Panel(f"[blue]{round(current_temperature - 273.15, 2)}°C",
|
||||||
current_temperature = info_main["temp"]
|
title="[bold]Temperature[/bold]"),
|
||||||
current_pressure = info_main["pressure"]
|
|
||||||
current_humidity = info_main["humidity"]
|
|
||||||
weather_description = info_weather[0]["description"]
|
|
||||||
|
|
||||||
print()
|
Panel(f"[blue]{current_pressure}hPa",
|
||||||
print(Columns([
|
title="[bold]Atmospheric Pressure[/bold]"),
|
||||||
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[/bold]"),
|
||||||
|
|
||||||
|
Panel(f"[blue]{weather_description}",
|
||||||
|
title="[bold]Description[/bold]"),
|
||||||
|
]))
|
||||||
|
|
||||||
Panel(f"[blue]{current_humidity}%",
|
case _:
|
||||||
title="[bold]Humidity[/bold]"),
|
print(Panel(data["message"],
|
||||||
|
title=f"[bold red]Error: {response.status_code}",
|
||||||
Panel(f"[blue]{weather_description}",
|
expand=False))
|
||||||
title="[bold]Description[/bold]"),
|
|
||||||
]))
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"Fehler: {response.status_code}")
|
|
||||||
print(response.text)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user