Skip to content

Instantly share code, notes, and snippets.

@xenji
Created March 30, 2013 19:44
Show Gist options
  • Save xenji/5278073 to your computer and use it in GitHub Desktop.
Save xenji/5278073 to your computer and use it in GitHub Desktop.
var redis = require("redis"),
client = redis.createClient();
var amqp = require('amqp');
var amqpc = amqp.createConnection({ host: 'somehost', login: 'guest', password: 'guest', vhost: '/' });
var geoip = require('geoip-lite');
var ll = require("lazylines");
amqpc.on('ready', function () {
amqpc.exchange('heatmap', {passive: true}, function(e){
process.stdin.resume();
var inp = new ll.LineReadStream(process.stdin, 'ascii');
inp.on("line", function (line) {
var tmp = ll.chomp(line).split(';'), ip = tmp[0], paths = tmp[1].split(',');
var geo = geoip.lookup(ip);
if (geo && geo['ll'])
for (var i in paths) {
client.get(paths[i], function(err, reply) {
e.publish('latlong.path', JSON.stringify({
src: geo['ll'],
dest: JSON.parse(reply)
}));
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment