Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Created March 2, 2011 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianloveswords/851204 to your computer and use it in GitHub Desktop.
Save brianloveswords/851204 to your computer and use it in GitHub Desktop.
var is_setup = null;
var hash_col = null;
var user_col = null;
var continue_execution = function(){
if ( !(is_setup && hash_col && user_col) ) return false;
sys.puts('setup and found collections');
start_stream();
return true;
};
var tweet_parser = function(tweet) {
var user = tweet.user.screen_name;
var tags = getHashtagsFromTweet(tweet);
var text = '';
if (tweet.retweeted_status) {
text = tweet.retweeted_status.text;
} else {
text = tweet.text;
}
if (tags.length > 0) {
tags.forEach(function(tag){
var tag_entry = {'tag' : tag, 'tweet' : {'screen_name': user, 'text': text } };
hash_col.insert(tag_entry, function(err, docs){
if (err) console.dir(err);
});
});
}
var user_entry = {'screen_name': user, 'tweet' : {'text': text, 'tags': tags }};
user_col.insert(user_entry, function(err, docs){
if (err) console.dir(err);
});
}
// setup stuff
db.createCollection('hashtag', function(err, collection){
console.log('ready with hashtag');
hash_col = collection;
continue_execution();
});
db.createCollection('user', function(err, collection){
console.log('ready with user');
user_col = collection;
continue_execution();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment