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