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

Created Dockerfile & Python File for the Application #175

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Use an official Python runtime as a parent image
FROM python:3.8
MAINTAINER label="Rohan Rustagi"
Copy link
Collaborator

Choose a reason for hiding this comment

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

LABEL maintainer="Rohan Rustagi" would be the modern way to write this

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback.

# Set the working directory in the container
WORKDIR /app

# Copy your Python script into the container
COPY *.py .
Copy link
Collaborator

Choose a reason for hiding this comment

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

This wouldn't scale well with projects as they grow, as it indiscriminately copies all files from the build context into the docker image


# Install the required dependencies (in this case, the ozon3 library)
RUN pip install ozon3

# Define the command to run your Python script
CMD ["python", "myapi.py"]
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ data = o3.get_historical_data(city='Houston') # data from 2014 onwards!
![Gif of Ozon3.get_multiple_city_air()](/src/media/example_get_multiple_city_air.gif)

![Gif of Ozon3.get_historical_data()](/src/media/example_get_historical_data.gif)

### Steps to use Docker for the Application


<img width="1440" alt="Screenshot 2023-11-05 at 11 58 03 PM" src="https://github.com/RohanRusta21/Ozon3/assets/110477025/23978e5d-9e17-4dd9-a5de-4bbc257a724b">


```shell
docker build -t <image-name> .
```

* `Single City`: For Fetching All details of city (eg. London, HongKong, Paris, Delhi, etc)

```shell
docker run <image-name> python getcityair.py <city_name>
```


* `Specific Parameter`: For Fetching Specific detail of city, For parameter please refer below values (eg. aqi, pm2.5, dew, etc)

```shell
docker run <image-name> python getspecificparam.py <city_name> <parameter>
```

### Air Quality Parameters

Ozon3 can fetch the following parameters:
Expand Down
22 changes: 22 additions & 0 deletions getcityair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import ozon3 as ooo

# Check if the city is provided as a command-line argument
if len(sys.argv) != 2:
print("Usage: python getcityair.py <city>")
sys.exit(1)

# Get the city from the command-line argument
city = sys.argv[1]

o3 = ooo.Ozon3('YOUR_TOKEN')

try:
# Fetch air quality data for the specified city
data = o3.get_city_air(city)
print(data)

except Exception as e:
print(f"Error: {str(e)}")


32 changes: 32 additions & 0 deletions getspecificparam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
import ozon3 as ooo

# Define a function to get a specific parameter for a given city
def get_specific_parameter(city, parameter):
o3 = ooo.Ozon3('YOUR_TOKEN')

try:
# Fetch air quality data for the specified city
data = o3.get_city_air(city)

# Check if the parameter exists in the data
if parameter in data:
return data[parameter]
else:
return f"Parameter '{parameter}' not found in the data."

except Exception as e:
return f"Error: {str(e)}"

# Check if the city and parameter are provided as command-line arguments
if len(sys.argv) != 3:
print("Usage: python getspecificparam.py <city> <parameter>")
sys.exit(1)

# Get the city and parameter from the command-line arguments
city = sys.argv[1]
parameter = sys.argv[2]

result = get_specific_parameter(city, parameter)
print(result)

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mypy
flake8
black
pre-commit
ozon3
flask

pytest==7.1.1
pytest-cov==4.0.0
Expand Down