cycle method added to auto cycle through tweets and exception handling is modified to capture all errors that raise from twitter

This commit is contained in:
AnithaPal 2016-07-27 17:02:40 -04:00
parent f29a15b8e4
commit 881518f1f3
10 changed files with 73 additions and 56 deletions

View file

@ -41,8 +41,6 @@ class Event < ActiveRecord::Base
scope :canceled, -> { where(state: 'canceled') }
scope :withdrawn, -> { where(state: 'withdrawn') }
scope :highlighted, -> { where(is_highlight: true) }
state_machine initial: :new do
state :new
@ -250,10 +248,10 @@ class Event < ActiveRecord::Base
end
##
#Compares event start_time, end_with with current time to predict current events
# Compares event start_time, end_with with current time to predict current events
#
def is_current?
Time.current >= self.start_time && Time.current <= end_time
def current?
Time.current >= self.start_time && Time.current <= self.end_time
end
private
@ -305,10 +303,10 @@ class Event < ActiveRecord::Base
end
##
#Compares event start_time, end_with with current time to predict current events
# Compares event start_time, end_with with current time to predict current events
#
def is_current?
Time.current >= self.start_time && Time.current <= end_time
def current?
Time.current >= self.start_time && Time.current <= self.end_time
end
end

View file

@ -3,23 +3,19 @@ class TwitterWrapper
def initialize
@client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["OSEM_TWITTER_CONSUMER_KEY"]
config.consumer_secret = ENV["OSEM_TWITTER_CONSUMER_SECRET"]
config.access_token = ENV["OSEM_TWITTER_ACCESS_TOKEN"]
config.access_token_secret = ENV["OSEM_TWITTER_ACCESS_TOKEN_SECRET"]
config.consumer_key = ENV['OSEM_TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['OSEM_TWITTER_CONSUMER_SECRET']
config.access_token = ENV['OSEM_TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['OSEM_TWITTER_ACCESS_TOKEN_SECRET']
end
end
##
#Fetches tweets from twitter api based on search_term and no_of_tweets
# Fetches tweets from twitter api based on search_term and no_of_tweets
#
def search_tweets(no_of_tweets, search_term)
begin
@client.search(search_term, result_type: "recent").take(no_of_tweets).collect
rescue Twitter::Error::TooManyRequests => error
sleep error.rate_limit.reset_in + 1
retry
end
@client.search(search_term, result_type: 'recent').take(no_of_tweets).collect
rescue
nil
end
end