Close

Setup node server

A project log for Wireless Flux Capacitor

A networked flux capacitor status indicator.

BeamsjrBeamsjr 04/24/2014 at 02:171 Comment

tonight I wrote a small node server to scrape the skulls from this project and update the flux capacitor delay with the amount of skulls  I have.  It will hit my project page every 15 minuets and if the value has changed will send a request to the flux capacitor to update.

var request = require('request');
var cheerio = require('cheerio');
var url = 'http://hackaday.io/project/594-Wireless-Flux-Capacitor';
var fc = 'http://192.168.1.98/delay/';
var prevLikes = 0;
console.log("Starting");
req();
function req() {
setTimeout(function(){
    request(url, function(err, resp, body) {
        if (err)
            throw err;
        $ = cheerio.load(body);
        var likes = $('#like_count').text();
        if(likes != prevLikes){
        var delay = 300 - parseInt(likes, 10);
        console.log(delay);
        prevLikes = likes;
        setDelay(delay);
        };
    });
    req();
}, 900000);
}
function setDelay(delay){
 request(fc + delay, function(err, resp, body) {
 console.log(body);
 });
}

Discussions

RodolpheH wrote 04/24/2014 at 05:52 point
Nice way to get skulls. If you could get a live webcam to see your Flux Capacitor, I'm pretty sure I will add a skull to see it changing is delay :)

  Are you sure? yes | no