Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
- simple cli
  • Loading branch information
EgorBlagov committed Dec 18, 2022
0 parents commit 9eccc35
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions main.py
@@ -0,0 +1,42 @@
from typing import Any
import asyncio
import abc
import aiohttp
import yarl
import requests


def simple_request(url: str, **query_params: Any) -> dict:
return requests.get(yarl.URL(url).update_query(**query_params)).json()

def weather_query():
while True:
city = input("Name a city: ")
response = simple_request(
"https://geocoding-api.open-meteo.com/v1/search", name=city
)
cities = response.get("results")

if not cities:
print("Found nothing")
continue

city = cities[0]
print(
"Found {name} ({country}) at latitude {latitude} and longitude {longitude}".format(
**city
)
)

response = simple_request(
"https://api.open-meteo.com/v1/forecast",
latitude=city["latitude"],
longitude=city["longitude"],
current_weather=1,
)

print(
f"Current temperature is {response['current_weather']['temperature']} °C"
)

weather_query()

0 comments on commit 9eccc35

Please sign in to comment.