Created
March 2, 2011 16:27
-
-
Save brianloveswords/851204 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 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