A NASA API explorer that can get near Earth object data, Mars rover pictures, and the Astronomy Picture of the Day.
Sign up for an API Key at- https://api.nasa.gov, then set it as an environment variable as follows-
$ export API_KEY=value
alternatively, if you don't wish to sign up, export the API key as follows-
$ export API_KEY=DEMO_KEY
Run the explorer with the following command line arguments-
-h
: Display the help page-as start_date end_date
: Explore NASA's Asteroids - NeoWs (Near Earth Object Web Service).-ap date file_name
: Explore the Astronomy Picture of the Day from NASA's APOD API.-m file_name date
: Explore NASA's Mars Rover Photos API.
$ python project.py [-h] [-as start_date end_date] [-ap date file_name] [-m file_name date]
Explorer is a NASA API explorer that gets data from NASA's open APIs: Asteroids - NeoWs, APOD, and Mars Rover Photos
The Astronomy Picture of the Day for December 30, 2022, accessed by-
$ python project.py -ap 2022-12-30 image
The implementation of Explorer, that has the following functions-
Validates the API key and command line arguments using Python's argparse and sys, and then calls the relevant functions below.
Writes NASA's Asteroids - NeoWs (Near Earth Object Web Service) data to a CSV file, based on the given start and end date.
- First using a regex(using Python's
re
module), it checks if the dates provided in the correct format, and then usesdatetime
to verify dates are valid. - Then, uses
requests
with NASA's Asteroids - NeoWs (Near Earth Object Web Service) API endpoint (https://api.nasa.gov/neo/rest/v1/feed?) with the provided dates and API key. - Then converts the response data to JSON and writes the data to a csv file using
DictWriter
, and returns the response status code.
Saves the Astronomy Picture of the Day from NASA's APOD API with the specified file name.
- First using a regex(using Python's
re
module), it checks if the dates provided in the correct format, then validates the file name. - Then, uses
requests
with the APOD API endpoint (https://api.nasa.gov/planetary/apod) with the provided date and API key. - Then converts the response data to JSON, gets the image url, and then using
requests
, gets the image and writes it to the specified file.
Accesses NASA's Mars Rover Photos API, and puts image urls taken by the Curiosity Mars rover in specified text file, and saves the first image found.
- First using a regex(using Python's
re
module), it checks if the dates provided in the correct format, validates the file name, and usesdatetime
to check if the date is valid. - Then, uses
requests
with the Mars Rover Photos API endpoint (https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos) with the provided date and API key. - Then converts the response data to JSON, gets the image urls, and writes them to a text file.
- Saves the first image found.
Unit tests for the functions implemented in project.py-
- Tests invalid dates.
- Verifies status codes.
- Tests invalid dates and file names.
- Verifies status codes.
- Tests invalid dates, file names, and file extensions.
- Verifies status codes.
The pip
-installable libraries required.
requests
- Clone the repository
- Run the Explorer as follows-
$ python project.py [-h] [-as start_date end_date] [-ap date file_name] [-m file_name date]
To clone the repository, execute-
$ git clone https://github.com/agentblack-6000/explorer.git