Created
May 15, 2011 18:40
-
-
Save whs/973415 to your computer and use it in GitHub Desktop.
Keyword tracker
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
// (C) 2011 Manatsawin Hanmongkolchai | |
// GNU GPL v3 | |
var twitter = require('twitter'); | |
var growl = require('growl'); | |
var twit = new twitter({ | |
consumer_key: '', | |
consumer_secret: '', | |
access_token_key: '', | |
access_token_secret: '', | |
}); | |
var firstLoad = true; | |
var maxLim = 5; | |
var limdata = []; | |
function notify(x){ | |
growl.notify(x.replace(/"/g, '\"'), {title: "Nodetrack"}); | |
} | |
function expireLim(){ | |
limdata = limdata.filter(function(x){ | |
if(x < new Date().getTime() - 60000) return false | |
else return true; | |
}) | |
} | |
twit.stream('user', {replies: "all", track: "มนัสวิน,ต่ายน้อย,กระต่าย,วิน"}, function(x){ | |
x.on('data', function(d){ | |
if(firstLoad){ | |
notify("Nodetrack loaded"); | |
firstLoad = false; | |
} | |
if(!d.text) return; | |
if(d.text.match(/(วิน|ต่าย)/)){ | |
expireLim(); | |
limdata.push(new Date().getTime()); | |
if(limdata.length > maxLim) console.log(d); | |
else notify(d.user.screen_name+": "+d.text) | |
} | |
}); | |
x.on('error', function(d){ | |
growl.notify("Stream error: "+d) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment