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

Fixed a couple of typos, simplified getters, introduced get_copyright #86

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 16 additions & 16 deletions apod_parser/apod_object_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@
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)
return response


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)
Expand Down
11 changes: 5 additions & 6 deletions apod_parser/apod_parser_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ get a Nasa api key by clicking <a href="https://api.nasa.gov/#signUp">here</a>.
```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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
```