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: Docker Weather API. #339

Open
wants to merge 3 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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
venv
__pycache__
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.8-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"]
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 <YOUR_DOCKER_ID/YOUR_IMAGE_NAME> .

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


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


def get_weather() -> None:
# write your code here
pass
params = {
"key": API_KEY,
"q": FILTERING
}
result = requests.get(URL, params=params).json()

print(
"Performing request to Weather API "
f"for city {result['location']['name']}...\n"
f"{result['location']['name']}/{result['location']['country']} "
f"{result['current']['last_updated']} Weather: "
f"{result['current']['temp_c']} Celsius, "
f"{result['current']['condition']['text']}"
)


if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
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
requests==2.31.0
urllib3==2.1.0
Loading