From 90c2f190309cb80be7b63f78718fbd4df27a7a08 Mon Sep 17 00:00:00 2001 From: Gerald Venzl Date: Fri, 12 Nov 2021 23:08:39 -0700 Subject: [PATCH 1/4] Fixed a couple of typos --- apod_parser/apod_parser_readme.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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) ``` From ea518bdd57e51f057df0a40484e9c1ee85ed83d8 Mon Sep 17 00:00:00 2001 From: Gerald Venzl Date: Fri, 12 Nov 2021 23:34:20 -0700 Subject: [PATCH 2/4] Fix typo in method name `get_explanation` had a redundant "i" in it. --- apod_parser/apod_object_parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apod_parser/apod_object_parser.py b/apod_parser/apod_object_parser.py index df2d627..2935bb2 100644 --- a/apod_parser/apod_object_parser.py +++ b/apod_parser/apod_object_parser.py @@ -14,9 +14,9 @@ def get_date(response): return date -def get_explaination(response): - explaination = response['explanation'] - return explaination +def get_explanation(response): + explanation = response['explanation'] + return explanation def get_hdurl(response): From 235d734d722f0bc4db40d0f4457242436f7978ee Mon Sep 17 00:00:00 2001 From: Gerald Venzl Date: Fri, 12 Nov 2021 23:37:45 -0700 Subject: [PATCH 3/4] Introduce get_copyright function --- apod_parser/apod_object_parser.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apod_parser/apod_object_parser.py b/apod_parser/apod_object_parser.py index 2935bb2..1100dc2 100644 --- a/apod_parser/apod_object_parser.py +++ b/apod_parser/apod_object_parser.py @@ -3,6 +3,10 @@ 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) From cb05b7367d7b5ac0d3242f92f04f4e507a8a7f2a Mon Sep 17 00:00:00 2001 From: Gerald Venzl Date: Fri, 12 Nov 2021 23:42:55 -0700 Subject: [PATCH 4/4] Simplify getters --- apod_parser/apod_object_parser.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/apod_parser/apod_object_parser.py b/apod_parser/apod_object_parser.py index 1100dc2..3a81b39 100644 --- a/apod_parser/apod_object_parser.py +++ b/apod_parser/apod_object_parser.py @@ -3,6 +3,7 @@ import os from PIL import Image + def get_copyright(response): return response['copyright'] @@ -14,39 +15,34 @@ def get_data(api_key): def get_date(response): - date = response['date'] - return date + return response['date'] def get_explanation(response): - explanation = response['explanation'] - return explanation + 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)