diff --git a/apod_parser/apod_object_parser.py b/apod_parser/apod_object_parser.py index df2d627..3a81b39 100644 --- a/apod_parser/apod_object_parser.py +++ b/apod_parser/apod_object_parser.py @@ -3,6 +3,11 @@ import os from PIL import Image + +def get_copyright(response): + return response['copyright'] + + 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) @@ -10,39 +15,34 @@ def get_data(api_key): def get_date(response): - date = response['date'] - return date + return response['date'] -def get_explaination(response): - explaination = response['explanation'] - return explaination +def get_explanation(response): + return response['explanation'] def get_hdurl(response): - hdurl = response['hdurl'] - return hdurl + return response['hdurl'] def get_media_type(response): - media_type = response['media_type'] - return media_type + return response['media_type'] + def get_service_version(response): - service_version = response['service_version'] - return service_version + return response['service_version'] def get_title(response): - service_version = response['title'] - return service_version + return response['title'] + def get_url(response): - url = response['url'] - return url + return response['url'] def download_image(url, date): - if os.path.isfile(f'{date}.png') == False: + if not os.path.isfile(f'{date}.png'): raw_image = requests.get(url).content with open(f'{date}.jpg', 'wb') as file: file.write(raw_image) diff --git a/apod_parser/apod_parser_readme.md b/apod_parser/apod_parser_readme.md index 86fccb7..38eb755 100644 --- a/apod_parser/apod_parser_readme.md +++ b/apod_parser/apod_parser_readme.md @@ -7,13 +7,12 @@ get a Nasa api key by clicking here. ```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 +2. Now call the `get_data` function and pass the `nasa api key` as the argument. Note, the 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) +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 @@ -44,7 +43,7 @@ the `get_url` function takes the dictionary we got above and returns the Standar 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). +the `get_media_type` function takes the dictionary we got above and returns the media type the file (might be a video or an image). ```python date = apod_object_parser.get_hdurl(response) @@ -54,13 +53,13 @@ date = apod_object_parser.get_hdurl(response) 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 +the `download_image` function 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. +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) ```