Created
March 30, 2013 19:44
-
-
Save xenji/5278073 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
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