Created
August 14, 2012 14:06
-
-
Save terenceponce/3349539 to your computer and use it in GitHub Desktop.
What's the best way to retrieve tweets that are on a given timeframe?
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
def live_tweets | |
tweets = Twitter.user_timeline(self.twitter_username, :include_entities => true) | |
max_id = nil | |
since_id = nil | |
last_id = nil | |
tweets.each do |tweet| | |
if tweet.created_at.utc <= self.time_end.utc | |
max_id = tweet.id | |
break | |
end | |
end | |
if first_event_tweet?(tweets) | |
since_id = first_event_tweet(tweets) | |
else | |
last_id = tweets.last.id | |
end | |
unless since_id | |
tweets = older_tweets(last_id) | |
# Lost my train of thought here | |
# idontknowwhatimdoing.jpg | |
end | |
def first_event_tweet(tweets) | |
since_id = nil | |
tweets.each do |tweet| | |
if tweet.created_at.utc <= self.time_start.utc | |
since_id = tweet.id | |
break | |
end | |
end | |
since_id | |
end | |
def first_event_tweet?(tweets) | |
since_id = nil | |
tweets.each do |tweet| | |
if tweet.created_at.utc <= self.time_start.utc | |
since_id = tweet.id | |
break | |
end | |
end | |
since_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment