initial commit
This commit is contained in:
commit
7e55524287
35
openweather.py
Executable file
35
openweather.py
Executable file
@ -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 ")
|
Loading…
Reference in New Issue
Block a user