Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexwkleung/nasa-libcurl-cli
A CLI program that fetches NASA API's and outputs them in prettified JSON format
https://github.com/alexwkleung/nasa-libcurl-cli
cli libcurl nasa-api nlohmann-json termstylist
Last synced: 23 days ago
JSON representation
A CLI program that fetches NASA API's and outputs them in prettified JSON format
- Host: GitHub
- URL: https://github.com/alexwkleung/nasa-libcurl-cli
- Owner: alexwkleung
- Created: 2022-09-04T17:43:14.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-06T01:07:24.000Z (about 2 years ago)
- Last Synced: 2024-10-15T19:24:43.119Z (23 days ago)
- Topics: cli, libcurl, nasa-api, nlohmann-json, termstylist
- Language: C++
- Homepage:
- Size: 2.4 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NASA-libcurl-CLI
![example](/img/example.png)
![example2](/img/example2.png)A CLI program that fetches [NASA API's](https://api.nasa.gov/) and outputs them in prettified JSON format.
Written in C++ using the [libcurl API](https://curl.se/libcurl/) and [nlohmann json parser](https://github.com/nlohmann/json). My library [TermStylist](https://github.com/alexwkleung/TermStylist) was also used for terminal colours.
**References:**
1. https://curl.se/libcurl/c/getinmemory.html
2. https://curl.se/libcurl/c/simple.html
3. https://json.nlohmann.me/api/basic_json/parse/
4. https://json.nlohmann.me/api/basic_json/dump/
# Installation
Clone the repository.
```bash
git clone
```Change directory.
```bash
cd NASA-libcurl-CLI
```Install cURL.
```bash
# homebrew
brew install curl# apt
sudo apt install curl# you will probably need to add cURL to your path to override system cURL.
# this should be specified by your package manager after installation.
```Change `CPPFLAGS` value to your cURL include directory if necessary.
```bash
# check library include directorycurl-config --cflags
``````make
# makefileCPPFLAGS = -std=c++17 -Wall -Wextra -g
```Change `LDFLAGS` value to your cURL lib directory if necessary.
```bash
# check library link directorycurl-config --libs
``````make
# makefileLDFLAGS =
```Create a text file to hold the NASA API key. Get your key [here](https://api.nasa.gov/).
```bash
# this directory (src/key.txt) is gitignored
touch src/key.txt
```Add key to the text file.
```txt
```
Build program.
```bash
make build
```Run a command line argument.
```bash
./src/a.o --
```# Options
**Command line arguments:**
`--apod` will call the function to fetch the Astronomy Picture of the day (APOD) API.
`--neo-feed` will call the function to fetch the Asteroids - NeoW Feed (Neo Feed) API.
`donki-sep` will call the function to fetch the DONKI Solar Energetic Particle (SEP) API.
`--insight` will call the function to fetch the InSight: Mars Weather Service API.
`--options` will call the function to take you to the options menu (selection prompt).
**Options menu (selection prompt):**
Typing `apod` will call the function to fetch the Astronomy Picture of the day (APOD) API.
Typing `neo-feed` will call the function to fetch the Asteroids - NeoW Feed (Neo Feed) API.
Typing `donki-sep` will call the function to fetch the DONKI Solar Energetic Particle (SEP) API.
Typing `insight` will call the function to fetch the InSight: Mars Weather Service API.
When you enter an option from either the menu or command line arguments, you might be asked to enter required fields to specify the API query before it fetches the JSON data string so that nlohmann json can parse it. For the ones that don't, it will go straight to fetching the JSON data string.
Here are the steps that will be executed in order:
1) Choose an option (apod, neo-feed, donki-sep, insight, etc).
2) Enter the required fields to specifiy the API query if applicable.
3) The JSON data string will be fetched by libcurl, then nlohmann json will parse that string and prettify the formatting for viewing pleasure.
4) The output of the prettified JSON will be present in the `json-out` directory, with file containing the naming scheme of `.json`. The prettified JSON is also outputted to the terminal.
# Issues
DONKI Solar Energetic Particle (SEP) API may have problems fetching data.