Skip to content

Commit

Permalink
Added config file and ability to follow Twitter users
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflinwood committed May 29, 2011
1 parent 9aa3e26 commit 50653fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ MongoDB - NoSQL database that uses BSON (similar to JSON) for inserting and retr

Mongo gem - Use the Mongo Ruby Driver directly, instead of an abstraction library

Yaml gem - Used for basic configuration tasks

Install
=============

Expand All @@ -16,12 +18,17 @@ Environment - requires Ruby and MongoDB.
gem install tweetstream
gem install twitter
gem install mongo
gem install yaml


Usage
==============

To run, change the USERNAME and PASSWORD to your Twitter username and password. Pick any tracking keywords you want, and add them to the @tracking_keywords array.
To run, open up config.yaml and change the USERNAME and PASSWORD to your Twitter account's username and password.

Pick any tracking keywords you want, and add them to the @tracking_keywords array.

This version has support for loading in one Twitter user's friends (the Twitter users they are following) and tracking their tweets as well - change the Twitter user's id from "jefflinwood" to your own or whomever. As long as the account isn't protected, you don't need the account's password or an OAuth authentication.

Open up a mongo shell and take a look at all the tweets you've collected! For sample data, I highly suggest "bieber" as a keyword.

Expand Down
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
username: USERNAME
password: PASSWORD
13 changes: 11 additions & 2 deletions tweeter-keeper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'rubygems'
require 'tweetstream'
require 'mongo'
require 'twitter'
require 'yaml'

@config = YAML.load_file('config.yaml')

#set up a connection to a local MongoDB
@db = Mongo::Connection.new.db("tweeterkeeper")
Expand All @@ -9,15 +13,20 @@
@tweets = @db.collection("tweets")

@tracking_keywords = Array['drupal','mongodb','three20'];
@follow_users = Twitter.friend_ids("jefflinwood").ids;

@client = TweetStream::Client.new('USERNAME','PASSWORD')
@client = TweetStream::Client.new(@config['username'],@config['password'])

@client.on_delete do |status_id, user_id|
puts "Removing #{status_id} from storage"
@tweets.remove({"status" => status_id})
end

@client.track(*@tracking_keywords) do |status|
@params = Hash.new;
@params[:follow] = @follow_users;
@params[:track] = @tracking_keywords;

@client.filter(@params) do |status|
puts "#{status.text}"
@tweets.insert(status)
end

0 comments on commit 50653fb

Please sign in to comment.