/NASA_Picture_of_the_Day_API

Uses a NASA API key to query the Astronomy Picture of the Day (APOD), then opens up the picture in your default browser.

Primary LanguagePython

NASA APOD Fetcher

This script fetches the Astronomy Picture of the Day (APOD) from NASA's API and displays it in your web browser.

Code

import urllib.request
import json
import webbrowser

Define APID

apodurl = 'https://api.nasa.gov/planetary/apod?' mykey = 'api_key=DEMO_KEY' ## replace DEMO_KEY with your nasa api key

Call the webservice

apodurlobj = urllib.request.urlopen(apodurl + mykey)

read the file-like object

apodread = apodurlobj.read()

decode json to python data structure

decodeapod = json.loads(apodread.decode('utf-8'))

display our pythonic data

print("\n\nConverted python data") print(decodeapod)

use browser to open the https url

input('\nPress Enter to open NASA Picture of the Day in Browser') webbrowser.open(decodeapod['url'])

Usage

To use this script, follow these steps:

  1. Obtain a NASA API key from NASA API Portal.
  2. Replace DEMO_KEY in the script with your own NASA API key.
  3. Run the script using Python 3.
  4. Press Enter when prompted to open the Astronomy Picture of the Day in your web browser.

Output

When you run the script, it will display the JSON response from the NASA API in your terminal and then open the picture in your default web browser.