Skip to content

Instantly share code, notes, and snippets.

@mauricesvay
Created March 8, 2013 10:22
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 mauricesvay/5115546 to your computer and use it in GitHub Desktop.
Save mauricesvay/5115546 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/node
var http = require('http');
var exec = require('child_process').exec;
var url = 'http://api.citybik.es/velib.json';
// var lat = '48.8836694';
// var lon = '2.3736453';
var id = 19030;
command = '/home/pi/blink1-tool -m 100 --rgb 50,50,50';
exec(command, function (error, stdout, stderr) {
if (error !== null) {
console.log(stdout);
process.exit(1);
} else {
getStatus();
}
});
function getStatus() {
var req = http.get(url, function(res){
var responseText = '';
res.on('data', function(data){
responseText += data.toString();
});
res.on('end', function(){
var data = JSON.parse(responseText);
var available = 0;
var color = '';
var command = '';
for (var i=0,l=data.length; i<l; i++) {
if (data[i].number == id) {
available = data[i].bikes;
}
}
console.log(available);
if (available < 3) {
color = "255,0,0";
} if (available >= 3 && available < 6) {
color = "255,204,51";
} if (available >= 6) {
color = "153,255,51";
}
command = '/home/pi/blink1-tool -m 100 --rgb ' + color;
exec(command, function (error, stdout, stderr) {
if (error !== null) {
console.log(stdout);
}
});
});
}).on('error', function(e){
console.log(e.message);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment