Skip to content

Instantly share code, notes, and snippets.

@sax1johno
Created August 29, 2016 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sax1johno/ec8310b595205d8ee24b3950ae240b8e to your computer and use it in GitHub Desktop.
Save sax1johno/ec8310b595205d8ee24b3950ae240b8e to your computer and use it in GitHub Desktop.
Cached Astronomy Picture of the Day

This flow will download the latest Astronomy Picture of the Day (APOD) from Nasa.gov and caches in memory.

It hits the API once every 24 hours, so you don't have to worry about reaching your quota.

This flow demonstrates a technique in caching data that can be used for other sites as well - for example, you can create your own "xxx of the day" from any site that offers a random API by simply calling that random API once every 24 hours (you can change this interval) and caching the result. Calls to the API will read from the cached version.

NOTE: to use this flow you must obtain a free API key from data.nasa.gov.

[
{
"id": "e50a0494.7b3488",
"type": "http in",
"z": "87767553.7027d8",
"name": "",
"url": "/api/apod",
"method": "get",
"swaggerDoc": "",
"x": 133,
"y": 811,
"wires": [
[
"20635998.ae8176"
]
]
},
{
"id": "8dc420cc.a5825",
"type": "http response",
"z": "87767553.7027d8",
"name": "",
"x": 687,
"y": 838,
"wires": []
},
{
"id": "ad882564.cc52b8",
"type": "inject",
"z": "87767553.7027d8",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"x": 140,
"y": 912,
"wires": [
[
"20635998.ae8176"
]
]
},
{
"id": "4a591a74.c05b14",
"type": "debug",
"z": "87767553.7027d8",
"name": "",
"active": true,
"console": "false",
"complete": "false",
"x": 719,
"y": 926,
"wires": []
},
{
"id": "85b43620.7cc438",
"type": "http request",
"z": "87767553.7027d8",
"name": "",
"method": "GET",
"ret": "txt",
"url": "https://api.nasa.gov/planetary/apod?api_key=YOUR_APIKEY_HERE",
"tls": "",
"x": 419,
"y": 1037,
"wires": [
[
"d449502a.c980b"
]
]
},
{
"id": "d449502a.c980b",
"type": "function",
"z": "87767553.7027d8",
"name": "Store latest APOD",
"func": "var latestApod = global.get('latestApod') || {};\nglobal.set('latestApod', msg.payload);\nmsg.reset = true;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 644.5,
"y": 1038,
"wires": [
[]
]
},
{
"id": "20635998.ae8176",
"type": "function",
"z": "87767553.7027d8",
"name": "Get APOD from cache",
"func": "msg.payload = global.get('latestApod');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 450.5,
"y": 861,
"wires": [
[
"8dc420cc.a5825",
"4a591a74.c05b14"
]
]
},
{
"id": "5e9ee18e.748ab",
"type": "inject",
"z": "87767553.7027d8",
"name": "Trigger APOD",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "86400",
"crontab": "",
"once": true,
"x": 164.5,
"y": 1039,
"wires": [
[
"85b43620.7cc438"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment