This script fetches the Astronomy Picture of the Day (APOD) from NASA's API and displays it in your web browser.
import urllib.request import json import webbrowserapodurl = 'https://api.nasa.gov/planetary/apod?' mykey = 'api_key=DEMO_KEY' ## replace DEMO_KEY with your nasa api key
apodurlobj = urllib.request.urlopen(apodurl + mykey)
apodread = apodurlobj.read()
decodeapod = json.loads(apodread.decode('utf-8'))
print("\n\nConverted python data") print(decodeapod)
input('\nPress Enter to open NASA Picture of the Day in Browser') webbrowser.open(decodeapod['url'])
To use this script, follow these steps:
- Obtain a NASA API key from NASA API Portal.
- Replace
DEMO_KEY
in the script with your own NASA API key. - Run the script using Python 3.
- Press Enter when prompted to open the Astronomy Picture of the Day in your web browser.
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.