Skip to content

Instantly share code, notes, and snippets.

@terenceponce
Created August 14, 2012 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terenceponce/3349539 to your computer and use it in GitHub Desktop.
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?
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