Example: NASA Module
Last updated
Last updated
This is some starter code which you could use if you want to use the NASA API. You will need to sign up at https://api.nasa.gov/ to get your API Key.
Some APIs do not keep their API public and you will need to go on their website and sign up to receive a unique API key.
Make sure you replace "DEMO_KEY"
with a real key from the NASA API in the API_KEY
variable.
import requests
# Base URL for NASA's Astronomy Picture of the Day (APOD) API
API_URL = "https://api.nasa.gov/planetary/apod"
API_KEY = "YOUR_KEY" # Replace with your NASA API key
def fetch_apod(date=None):
"""Functions to interact with the NASA APOD API."""
date = input("Enter a date (YYYY-MM-DD) or press Enter for today's APOD: ")
apod_data = fetch_apod(date if date else None)
display_apod(apod_data)