From 78389e12ec2ddcfb2a8e24f0da616b36c2a6385b Mon Sep 17 00:00:00 2001 From: VR Date: Mon, 13 Jan 2025 20:33:16 +0200 Subject: [PATCH 1/2] solution --- .dockerignore | 5 +++++ Dockerfile | 12 ++++++++++++ app/main.py | 22 ++++++++++++++++++++-- requirements.txt | Bin 111 -> 556 bytes 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..342bf368 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.venv +README.md +result.png +.github +checklist.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c887a695 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.9-slim +LABEL maintainer="vladrymarchuk@gmai.com" + + +WORKDIR /app + +COPY requirements.txt requirements.txt +RUN pip install -r requirements.txt + +COPY app/main.py /app + +CMD ["python", "main.py"] diff --git a/app/main.py b/app/main.py index 16dd4058..9d6890ab 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,24 @@ +import os + +import requests + + def get_weather() -> None: - # write your code here - pass + API_KEY = os.getenv("API_KEY", "No API key provided") + CITY = os.getenv("CITY", "Kyiv") + url = f"https://api.weatherapi.com/v1/current.json?key={API_KEY}&q={CITY}&aqi=no" + response = requests.get(url) + if response.status_code == 200: + weather_data = response.json() + weather_data = ( + weather_data["location"]["country"], + weather_data["location"]["name"], + weather_data["location"]["localtime"], + f"Weather: {weather_data['current']['temp_c']} Celsius", + weather_data["current"]["condition"]["text"]) + print(weather_data) + else: + print(f"Error: {response.status_code}") if __name__ == "__main__": diff --git a/requirements.txt b/requirements.txt index 03c40c2554ce9d2d37831a6910326142c71e1f3f..2b962ba8372a8a98ac86ffcbe21db9be9a69c3a9 100644 GIT binary patch literal 556 zcmZuvTMmLS5S(ulj{>2hQ9nFPRaD{w#A>34S7){$CYq*!vh@_Kp%t_Bw@xJDQw zMb4dJhyhk8SPLkz;f{!`ML9lGI5Hw~2X8tB@d-|-cslaify{^Lh%aqf&b&C04%>-v$i41gzSov%J`X{(ixuLShl6{Gx9G)pU zcGmVcvHnV|t={Ew?bME(+saf5OC{FSm`YVst!Ca%yQIeUgLBs1$ns4?v2gvY`kBOO%CjL)lZZM!BDXut&FxCmfvaTt{NvL93vcSqQY`=g literal 111 zcmYMs%L;%X5QX8r@8aMk!4^Ku1R9c!me%v9L9{&I4<{ttymiiifQf~7aU{wOTg+6Q nQ!s=4%5ml9J8IBB-grh_lCPX_A64`-!-_9 Date: Mon, 13 Jan 2025 20:35:47 +0200 Subject: [PATCH 2/2] fix flake8 --- app/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 9d6890ab..1243fd30 100644 --- a/app/main.py +++ b/app/main.py @@ -4,9 +4,10 @@ def get_weather() -> None: - API_KEY = os.getenv("API_KEY", "No API key provided") - CITY = os.getenv("CITY", "Kyiv") - url = f"https://api.weatherapi.com/v1/current.json?key={API_KEY}&q={CITY}&aqi=no" + api_key = os.getenv("API_KEY", "No API key provided") + city = os.getenv("CITY", "Kyiv") + url = (f"https://api.weatherapi.com/v1/current.json?key=" + f"{api_key}&q={city}&aqi=no") response = requests.get(url) if response.status_code == 200: weather_data = response.json()