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 #346

Open
wants to merge 7 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 @@
.env
venv/
.python-version
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"]
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 prochihor/docker-weather-api`.

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

import os
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
params = {
"q": FILTERING,
"key": API_KEY
}

response = requests.get(URL, params=params)

Choose a reason for hiding this comment

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

you forgot to print: Performing request to Weather API for city Paris...


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

weather_data = response.json()
capital = weather_data["location"]["name"]
country = weather_data["location"]["country"]
localtime = weather_data["location"]["localtime"]
temperature = weather_data["current"]["temp_c"]
weather = weather_data["current"]["condition"]["text"]
print(
f"{capital}/{country} {localtime} "
f"Weather: {temperature} Celsius, {weather}"
)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ flake8-annotations==2.9.1
flake8-quotes==3.3.1
flake8-variables-names==0.0.5
pep8-naming==0.13.2
requests~=2.31.0
python-dotenv~=1.0.0
Loading