Created
August 29, 2010 16:01
-
-
Save matschaffer/556411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Drives the Bieber-graph at http://awesometown.no.de. | |
// Run through a recent-ish version of node.js. | |
var sys = require('sys'), | |
http = require('http'), | |
twitter = http.createClient(80, 'search.twitter.com'), | |
twitterPath = "/search.json?&q=bieber", | |
chartId = "4c7a650eba12e9c41d000005", | |
interval = 5000, | |
lastId = null; | |
function postValue(id, value) { | |
var req, http = require('http'), | |
simulchart = http.createClient(80, 'awesometown.no.de'), | |
simulchartPath = "/graphs/" + id + "/appendValue", | |
body = "value=" + value, | |
headers = { "Host": simulchart.host, | |
"Content-Length": body.length, | |
"Content-Type": "application/x-www-form-urlencoded"}; | |
req = simulchart.request('POST', simulchartPath, headers); | |
req.write(body); | |
req.end(); | |
} | |
function update() { | |
var count, results, req, reqPath, body = ""; | |
reqPath = lastId ? twitterPath + "&since_id=" + lastId : twitterPath; | |
req = twitter.request('GET', reqPath, {"Host": twitter.host}); | |
req.end(); | |
req.on('response', function (res) { | |
res.on('data', function(chunk) { | |
body += chunk; | |
}); | |
res.on('end', function() { | |
results = JSON.parse(body).results; | |
if (results) { | |
count = results.length; | |
console.log("Saw " + count + " tweets"); | |
if (results[0]) lastId = results[0].id; | |
postValue(chartId, count); | |
} | |
setTimeout(update, interval); | |
}); | |
}); | |
} | |
update(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# cut/awk combo reads solaris style output, cause that's what joyent is. | |
while true; do | |
curl -d value=`uptime | cut -d':' -f3 | cut -d, -f1 | awk '{print $1}'` http://awesometown.no.de/graphs/4c7acd5ca121636840000002/appendValue | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment