Skip to content

Commit

Permalink
Finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksa-32 committed Jan 21, 2025
1 parent 3db665d commit 2f1886e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.11
LABEL authors="user"

ENV PYTHOUNNBYFFERED 1

WORKDIR app/

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .

CMD ["python", "manage.py", "runserver", "0.0.0.0.8000"]
29 changes: 27 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import os
import requests
import sys


def get_weather() -> None:
# write your code here
pass
api_key = os.getenv("WEATHER_API_KEY")
if not api_key:
print("Error: WEATHER_API_KEY environment variable not set.",
file=sys.stderr)
sys.exit(1)

url = f"https://api.weatherapi.com/v1/current.json?key={api_key}&q=Paris"

try:
response = requests.get(url, timeout=10)
response.raise_for_status()
data = response.json()

location = data["location"]["name"]
country = data["location"]["country"]
temp_c = data["current"]["temp_c"]
condition = data["current"]["condition"]["text"]

print(f"Weather in {location}, {country}: {temp_c}°C, {condition}")
except (requests.RequestException, KeyError) as e:
print(f"Error fetching or parsing weather data: {e}", file=sys.stderr)
sys.exit(1)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ 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

0 comments on commit 2f1886e

Please sign in to comment.