-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
389 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ lib/ | |
apod/__pycache__/ | ||
.elasticbeanstalk/ | ||
*.zip* | ||
Archive.zip | ||
Archive.zip | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3-alpine | ||
|
||
WORKDIR /usr/src/app | ||
COPY requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
COPY . . | ||
EXPOSE 5000 | ||
ENTRYPOINT ["python"] | ||
CMD ["application.py"] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import requests | ||
import json | ||
import os | ||
from PIL import Image | ||
|
||
def get_data(api_key): | ||
raw_response = requests.get(f'https://api.nasa.gov/planetary/apod?api_key={api_key}').text | ||
response = json.loads(raw_response) | ||
return response | ||
|
||
|
||
def get_date(response): | ||
date = response['date'] | ||
return date | ||
|
||
|
||
def get_explaination(response): | ||
explaination = response['explanation'] | ||
return explaination | ||
|
||
|
||
def get_hdurl(response): | ||
hdurl = response['hdurl'] | ||
return hdurl | ||
|
||
|
||
def get_media_type(response): | ||
media_type = response['media_type'] | ||
return media_type | ||
|
||
def get_service_version(response): | ||
service_version = response['service_version'] | ||
return service_version | ||
|
||
|
||
def get_title(response): | ||
service_version = response['title'] | ||
return service_version | ||
|
||
def get_url(response): | ||
url = response['url'] | ||
return url | ||
|
||
def download_image(url, date): | ||
if os.path.isfile(f'{date}.png') == False: | ||
raw_image = requests.get(url).content | ||
with open(f'{date}.jpg', 'wb') as file: | ||
file.write(raw_image) | ||
|
||
else: | ||
return FileExistsError | ||
|
||
|
||
def convert_image(image_path): | ||
path_to_image = os.path.normpath(image_path) | ||
|
||
basename = os.path.basename(path_to_image) | ||
|
||
filename_no_extension = basename.split(".")[0] | ||
|
||
base_directory = os.path.dirname(path_to_image) | ||
|
||
image = Image.open(path_to_image) | ||
image.save(f"{base_directory}/{filename_no_extension}.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# apod_object_parser | ||
|
||
get a Nasa api key by clicking <a href="https://api.nasa.gov/#signUp">here</a>. | ||
|
||
## How to use | ||
1. import the file | ||
```python | ||
import apod_object_parser | ||
``` | ||
2. Now call the `get_data` function and pass the `nasa api key` as the argument. Note api_key is a string. The response returned will be a Dictionary. Now you can parse the dictionary too | ||
|
||
```python | ||
response = apod_object_parser.get_data(##Pass In Your API key here) | ||
``` | ||
### get_date | ||
|
||
the `get_date` function takes the dictionary we got above and returns the date. | ||
|
||
```python | ||
date = apod_object_parser.get_date(response) | ||
``` | ||
### get_explaination | ||
the `get_explaination` function takes the dictionary we got above and returns the explaintion. | ||
|
||
```python | ||
date = apod_object_parser.get_explaination(response) | ||
``` | ||
### get_hdurl | ||
the `get_hdurl` function takes the dictionary we got above and returns the High Definition url of the image. | ||
|
||
```python | ||
date = apod_object_parser.get_hdurl(response) | ||
``` | ||
### get_title | ||
the `get_title` function takes the dictionary we got above and returns the title of the image. | ||
|
||
```python | ||
date = apod_object_parser.get_title(response) | ||
``` | ||
### get_url | ||
the `get_url` function takes the dictionary we got above and returns the Standard definition url of the image. | ||
|
||
```python | ||
date = apod_object_parser.get_hdurl(response) | ||
``` | ||
### get_media_type | ||
the `get_media_type` function takes the dictionary we got above and returns the media type the file (might be a video of a image). | ||
|
||
```python | ||
date = apod_object_parser.get_hdurl(response) | ||
``` | ||
|
||
## Other functions | ||
there are also other functions that might help you in situations | ||
|
||
### download_image | ||
the `download_image` finction takes the url (hdurl or url) and the date from the function `get_date` and downloads the image in the current directory and with the file name of the date. the image downloaded is in the .jpg format | ||
```python | ||
apod_object_parser.download_image(url, date) | ||
``` | ||
|
||
### convert_image | ||
sometimes the image we downloaded above might not be in the right format (.jpg) so you may call `convert_image` function to convert the image into .png. takes the `image_path` parameter which is the filepath. | ||
```python | ||
apod_object_parser.convert_image(image_path) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.