Skip to content

Instantly share code, notes, and snippets.

@jdcauley
Created June 9, 2015 23:51
Show Gist options
  • Save jdcauley/9b83242c3b60d5c97711 to your computer and use it in GitHub Desktop.
Save jdcauley/9b83242c3b60d5c97711 to your computer and use it in GitHub Desktop.
/**
* Bootstrap
* (sails.config.bootstrap)
*
* An asynchronous bootstrap function that runs before your Sails app gets lifted.
* This gives you an opportunity to set up your data model, run jobs, or perform some special logic.
*
* For more information on bootstrapping your app, check out:
* http://sailsjs.org/#/documentation/reference/sails.config/sails.config.bootstrap.html
*/
module.exports.bootstrap = function(cb) {
// It's very important to trigger this callback method when you are finished
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap)
stream.start();
cb();
};
var Twitter = require('twitter');
var twitter = new Twitter({
consumer_key: sails.config.secrets.twitter.consumer_key,
consumer_secret: sails.config.secrets.twitter.consumer_secret,
access_token_key: sails.config.secrets.twitter.access_token_key,
access_token_secret: sails.config.secrets.twitter.access_token_secret
});
module.exports = {
start: function(){
console.log('start stream');
twitter.stream('statuses/filter', {locations: '-122.75,36.8,-121.75,37.8', granularity: 'city'}, function(stream){
stream.on('data', function(tweet) {
console.log(tweet.text + ' - @' + tweet.user.screen_name);
console.log('------------------');
Tweet.create(tweet, function(err, status){
if(err){
Tweet.publishCreate(err);
}
if(status){
Tweet.publishCreate(status);
}
});
});
});
stream.on('error', function(error) {
console.log(error);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment