From ebe2f190d6b04b9b343c827e83b2dd7ad0a5e5cf Mon Sep 17 00:00:00 2001 From: Frezworx Date: Fri, 10 Jan 2025 12:07:51 +0200 Subject: [PATCH] Add weather data retrieval and display functionality --- Dockerfile | 13 +++++++++++++ app/main.py | 19 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..10ba1627 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.12.8-alpine3.20 +LABEL authors="frezworx" + +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app + +COPY requirements.txt requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "app/main.py"] diff --git a/app/main.py b/app/main.py index 19134200..86d5e00c 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,6 @@ import os +from pprint import pprint + from dotenv import load_dotenv import requests @@ -11,9 +13,22 @@ def get_weather() -> None: - print(API_KEY) + print(f"Performing request to Weather API for city {FILTERING}...") response = requests.get(f"{URL}current.json?key={API_KEY}&q={FILTERING}") - print(response.json()) + data = response.json() + + location = data.get("location", {}) + current = data.get("current", {}) + + city = location.get("name", "") + country = location.get("country", "") + date = location.get("localtime", "") + temperature = current.get("temp_c", "") + condition = current.get("condition", {}).get("text", "") + + print( + f"{city}/{country} {date} Weather: {temperature} Celsius, {condition}" + ) if __name__ == "__main__":