45 lines
1.3 KiB
Python
Executable File
45 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
from rich import print
|
|
from rich.panel import Panel
|
|
from rich.prompt import Prompt
|
|
from rich.columns import Columns
|
|
|
|
api_key = Prompt.ask("Enter your Api Key", password=True)
|
|
city_name = Prompt.ask("Enter your City", default="Göttingen")
|
|
|
|
base_url = "https://api.openweathermap.org/data/2.5/weather?"
|
|
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
|
|
response = requests.get(complete_url)
|
|
|
|
data = response.json()
|
|
|
|
if response.status_code == 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"]
|
|
|
|
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_humidity}%",
|
|
title="[bold]Humidity[/bold]"),
|
|
|
|
Panel(f"[blue]{weather_description}",
|
|
title="[bold]Description[/bold]"),
|
|
]))
|
|
|
|
else:
|
|
print(f"Fehler: {response.status_code}")
|
|
print(response.text)
|