~josealberto4444/apodnasabot

b589bb0ab0d17ce33d8682094aead7bafd0c5bfc — José Alberto Orejuela García 2 years ago bd0b224
Save JSON to file
1 files changed, 4 insertions(+), 1 deletions(-)

M api.py
M api.py => api.py +4 -1
@@ 25,8 25,11 @@ baseurl = 'https://api.nasa.gov/planetary/apod'
payload = {'api_key': api_key}
r = requests.get(baseurl, params = payload)
api_response = r.json()

filename = 'data/' + api_response['date']

with open(filename + '.json', 'wt') as f:
    f.write(str(api_response))

if api_response['media_type'] == 'image':
    r = requests.get(api_response['hdurl'])
    filename = filename + '.jpg'