34
$\begingroup$

I ♥ NASA. You ♥ NASA. We all ♥ NASA.

So how can I use the images and things they expose in their APIs in Mathematica?

$\endgroup$

1 Answer 1

40
$\begingroup$

I built a ServiceConnect paclet for this (details on how I did this can be found at the end of this post).

You can access it like so:

PacletInstall[
 "ServiceConnection_NASA",
 "Site"->
  "http://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"
 ]

paclet

(note that unless you have BTools installed and have loaded the PacletTools package (e.g. by just calling PacletUpload raw to get the autoloader to run) you won't get this formatted form)

Then just connect and have at it!

$so = ServiceConnect["NASA"]

nasdasdasd

Pic of the Day

$so["PictureOfTheDay"]["Image"]

nasa img

Earth

$so["EarthImages",
  "Date" -> Today - Quantity[1, "Weeks"], 
  "ImportImages" -> True,
  "ImportSelection" -> ;; 3
  ][All, {"Image", "caption"}]

images

Mars

$so["MarsImages", 
  "earth_date" -> Today, "ImportImages" -> True, 
  "ImportSelection" -> {1}
  ][2]

asdasd

And more!

You can get the currently supported requests like so:

$so["Requests"]

{"APIKey", "Authentication", "EarthImages", "ID", \
"ImportEarthImages", "Information", "LandsatAssets", "LandsatImages", \
"MarsImage", "MarsRoverData", "Name", "NeoFeed", "NeoLookup", \
"Patents", "PictureOfTheDay", "RawRequests", "RequestData", \
"RequestParameters", "RoverCameras"}

And you can figure out what to pass to each using the "RequestParameters" like so:

$so["RequestParameters", "Request" -> "Patents"]

<|"Parameters" -> {"api_key", "query", "concept_tags", "limit"}, 
 "Required" -> {}|>

$so["Patents"]["results", 1, "title"]

"Selective functionalization of carbon nanotubes based upon distance  \
   traveled"

If you want me to implement more requests I can easily do so


Construction Process

I built this according to the process laid out in my answer to the question Creating a custom web API ServiceConnection.

The actual construction notebook can be obtained here so you can see what went into building it.

Essentially, I just have a template notebook that you fill out and which formats a call to the CustomServiceConnection function in my BTools package.

$\endgroup$
8
  • $\begingroup$ I love NASA⊙ Also. $\endgroup$
    – quintumnia
    Commented Jan 14, 2018 at 17:03
  • 1
    $\begingroup$ +1 of course but please include at least the very initial implementation. We try to avoid link based answers as they can become useless once links are invalid. Would be also nice to link BTools if you mention them. $\endgroup$
    – Kuba
    Commented Jan 15, 2018 at 6:19
  • $\begingroup$ @Kuba that's handled. I didn't go into the actual gory details but mostly just linked to a construction notebook and my previous answer on building ServiceConnections $\endgroup$
    – b3m2a1
    Commented Jan 15, 2018 at 8:14
  • 1
    $\begingroup$ It is not about illumination but a self contained content. Once your wolfram cloud account is gone this answer won't be so helpful. $\endgroup$
    – Kuba
    Commented Jan 15, 2018 at 8:46
  • 2
    $\begingroup$ @b3m2a1 You are right, it is not a must so let's stay with more example focused answers linked together with github and wpc. $\endgroup$
    – Kuba
    Commented Jan 15, 2018 at 8:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.