Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #364

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
venv
.flake8
checklist.md
README.md
result.png

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line

14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.11.4-slim
LABEL maintainer="[email protected]"

ENV PYTHONUNBUFFERED 1

WORKDIR app/

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

COPY . .

CMD ["python", "app/main.py"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ So in this task requirements are next:
And to pass environment variables to docker container use `-e` flag.
- Don't forget to add `.dockerignore` file to your PR;
- You must *modify* this line with correct command to pull your image:
COMMAND=`docker pull <YOUR_DOCKER_ID/YOUR_IMAGE_NAME>`.
COMMAND=`docker pull petrykivd/docker-weather`.

<details>
<summary><strong>Hint</strong></summary>
Expand Down
27 changes: 25 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
import os

import requests

from dotenv import load_dotenv, find_dotenv

load_dotenv(find_dotenv())

URL = "http://api.weatherapi.com/v1/current.json"
FILTERING = "Paris"
API_KEY = os.environ.get("API_KEY")


def get_weather() -> None:
# write your code here
pass

response = requests.get(url=URL, params={"key": API_KEY, "q": FILTERING})
print("Performing request to Weather API for city Paris...")
if response.status_code != 200:
print(f"Request error, Status code: {response.status_code} != 200")
return
data = response.json()
print(f'{data["location"]["name"]}'
f'/{data["location"]["country"]}'
f' {data["location"]["localtime"]}'
f' Weather: {data["current"]["temp_c"]} Celsius,'
f' {data["current"]["condition"]["text"]}')


if __name__ == "__main__":
Expand Down
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
attrs==23.1.0
certifi==2023.11.17
charset-normalizer==3.3.2
flake8==5.0.4
flake8-annotations==2.9.1
flake8-quotes==3.3.1
flake8-variables-names==0.0.5
idna==3.6
mccabe==0.7.0
pep8-naming==0.13.2
pycodestyle==2.9.1
pyflakes==2.5.0
python-dotenv==1.0.0
requests==2.31.0
urllib3==2.1.0
Loading