commit 7e55524287955bacc9b9e81dd988686bbe698202 Author: Marius Alwan Meyer Date: Fri Sep 29 11:38:03 2023 +0200 initial commit diff --git a/openweather.py b/openweather.py new file mode 100755 index 0000000..be672a7 --- /dev/null +++ b/openweather.py @@ -0,0 +1,35 @@ +#!/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"] + + print(Columns([ + Panel(f"[bold]Temperature[/bold]\n[blue]{current_temperature} K", expand=True), + Panel(f"[bold]Atmospheric Pressure[/bold]\n[blue]{current_pressure} hPa", expand=True), + Panel(f"[bold]Humidity[/bold]\n[blue]{current_humidity} %", expand=True), + Panel(f"[bold]Description[/bold]\n[blue]{weather_description}", expand=True) + ])) + +else: + print(" City Not Found ") \ No newline at end of file