-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seed tweets by migrating back thru the timeline
- Loading branch information
Josh Schairbaum
committed
Apr 20, 2012
1 parent
9b6e228
commit ea996a2
Showing
6 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ | |
/tmp | ||
|
||
*#* | ||
*~* | ||
*~* | ||
credentials.sh |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Tweet | ||
|
||
KARL = 'dadboner' | ||
|
||
include Mongoid::Document | ||
field :created_at, :type => Time | ||
field :twitter_id, :type => String, :unique => true | ||
field :text, :type => String | ||
|
||
def self.seed_tweets | ||
tweets = Twitter.user_timeline(KARL, :trim_user => true, :count => 200) | ||
max_id = tweets.map{|t| t.id}.sort.first | ||
|
||
while tweets.any? | ||
tweets = Twitter.user_timeline(KARL, :trim_user => true, :count => 200, :max_id => max_id) | ||
max_id = tweets.map{|t| t.id}.sort.first | ||
|
||
tweets.each do |twoot| | ||
tweet = create(:twitter_id => twoot.id.to_s, :created_at => twoot.created_at, :text => twoot.text) | ||
end | ||
end | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Twitter.configure do |config| | ||
config.consumer_key = ENV['TWITTER_CONSUMER_KEY'] | ||
config.consumer_secret = ENV['TWITTER_CONSUME_SECRET'] | ||
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN'] | ||
config.oauth_token_secret = ENV['TWITTER_OAUTH_TOKEN_SECRET'] | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
describe Tweet do | ||
after(:each) do | ||
Tweet.destroy_all | ||
end | ||
|
||
describe ".seed_tweets" do | ||
it "creates tweets from the feed" do | ||
tweets = [mock("tweet", { :created_at => Time.now, :text => "tweets", :id_str => "12345678910" }), | ||
mock("tweet", { :created_at => Time.now, :text => "tweets", :id_str => "23456789101"}) ] | ||
|
||
Twitter.stub!(:user_timeline).and_return(tweets) | ||
|
||
Tweet.seed_tweets | ||
Tweet.count.should == 2 | ||
end | ||
|
||
it "grabs tweets from Twitter" do | ||
Twitter.should_receive(:user_timeline).and_return([]) | ||
Tweet.seed_tweets | ||
end | ||
end | ||
end |
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