2023-09-29 11:38:03 +02:00
|
|
|
#!/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
|
|
|
|
|
|
|
|
city_name = Prompt.ask("Enter your City", default="Göttingen")
|
|
|
|
api_key = Prompt.ask("Enter your Api Key")
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
x = response.json()
|
|
|
|
|
|
|
|
if x["cod"] != "404":
|
|
|
|
|
|
|
|
y = x["main"]
|
|
|
|
current_temperature = y["temp"]
|
|
|
|
current_pressure = y["pressure"]
|
|
|
|
current_humidity = y["humidity"]
|
|
|
|
z = x["weather"]
|
|
|
|
weather_description = z[0]["description"]
|
|
|
|
|
2023-09-29 13:05:54 +02:00
|
|
|
print()
|
2023-09-29 11:38:03 +02:00
|
|
|
print(Columns([
|
2023-09-29 13:05:54 +02:00
|
|
|
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]"),
|
2023-09-29 11:38:03 +02:00
|
|
|
]))
|
|
|
|
|
|
|
|
else:
|
|
|
|
print(" City Not Found ")
|