Skip to content

Instantly share code, notes, and snippets.

@kmicheli
Last active September 25, 2018 04:40
Show Gist options
  • Save kmicheli/ea20855e68b7549ecd6893779cf20a6f to your computer and use it in GitHub Desktop.
Save kmicheli/ea20855e68b7549ecd6893779cf20a6f to your computer and use it in GitHub Desktop.
console.log(process.argv[0], process.argv[1], process.argv[2], process.argv[3]);
if (process.argv.length < 4){
console.log('Please type in station ID and Observation ID');
process.exit();
}
const fs = require('fs')
const request = require('superagent')
var stationID = process.argv[2];
var observationID = process.argv[3];
var apiBase = 'https://network.satnogs.org/api/observations/'
var url = apiBase + observationID + '/?format=json&page=1&ground_station=' + stationID
fs. mkdirSync('station' + stationID +'_observation' + observationID);
console.log('station' + stationID +'_observation' + observationID + ' new folder created');
request.get(url) // fetches the JSON
.then(response => {
// we get the waterfall out of the JSON
var waterfall = response.body.waterfall
var audio = response.body.payload
if (waterfall && waterfall.trim() !== '') {
// if exists, we try to fetch the waterfall...which is png
request.get(waterfall)
.then(res2 => {
fs.writeFile('./'+ 'station' + stationID + '_observation' + observationID + '/observation_' + observationID + '.png', res2.body, (err) => {
if (err) throw err;
console.log("observation_" + observationID + '.png has been saved to the new folder.');
});
})
}
if (audio && audio.trim() !== '') {
// if exists, we try to fetch the waterfall - a png file
// parse the audio url here and find final portion of the url filename
request.get(audio)
.then(res2 => {
fs.writeFile('./'+ 'station' + stationID + '_observation' + observationID + '/observation_' + observationID + '.ogg', res2.body, (err) => {
if (err) throw err;
console.log("observation_" + observationID + '.ogg has been saved to the new folder.');
});
})
}
})
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "example.js",
"scripts": {},
"author": "Karina Micheli",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"prompt": "^1.0.0",
"request": "^2.88.0",
"superagent": "^4.0.0-beta.5"
}
}
@kmicheli
Copy link
Author

kmicheli commented Sep 25, 2018

This is a command line application that can pull the data from the satnogs api and print it on screen (or in the case of audio/image download it to your harddisk).

This app takes two user inputs:
station id
observation id (for exact observation)

If the observation has audio and/or image data, it will create a new folder in the application folder, and download + store the file inside the new folder.

To begin, open terminal and navigate to the folder which keeps the app.
To run the app, type: node app.js stationID observationID
Keep in mind, stationID and observationID should be replaced with the specific station and observation you are looking for.
The application will create a new folder within the app folder, naming it after the stationID and observationID, and save any .png or .ogg files inside of it.

I would like to credit August Black for assistance with this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment