feat: weather client
This commit is contained in:
@@ -1,5 +1,16 @@
|
|||||||
|
from geo_locator import get_geo, get_ip
|
||||||
|
from weather_client import get_weather
|
||||||
|
from dotenv import load_dotenv, find_dotenv, dotenv_values
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Hello from weather-fetch-lab!")
|
loaded = load_dotenv()
|
||||||
|
print(f"{find_dotenv()} {loaded} {dotenv_values(find_dotenv())}")
|
||||||
|
ip: str = get_ip()
|
||||||
|
print(f"Hello, {ip}")
|
||||||
|
geo = get_geo()
|
||||||
|
print(f"You are at {geo}")
|
||||||
|
get_weather(geo.lat, geo.lot)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from cnet import json
|
||||||
|
|
||||||
|
|
||||||
|
def get_weather(lat: str, lon: str):
|
||||||
|
base_url = os.getenv(
|
||||||
|
"WEATHER_API_BASE_URL", "https://api.openweathermap.org/data/2.5/forecast"
|
||||||
|
)
|
||||||
|
api_key = os.getenv("WEATHER_API_KEY", "no")
|
||||||
|
|
||||||
|
print(f"api_key: {api_key}")
|
||||||
|
url = f"{base_url}?lat={lat}&lon={lon}&appid={api_key}&units=metric&lang=ru"
|
||||||
|
return json(url)
|
||||||
Reference in New Issue
Block a user