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

@ -1,6 +1,17 @@
$(document).ready(function() {
// will call refreshCurrentEvents every 15 minutes
setInterval(refreshCurrentEvents, 900000)
setInterval(refreshCurrentEvents, 900000)
// To cycle through tweets
var tweets = $('div[id^="tweet"]').hide();
var i = 0;
(function cycle() {
tweets.eq(i).show(0)
.delay(5000)
.hide(0, cycle);
i = ++i % tweets.length;
})();
});
function refreshCurrentEvents(){

View file

@ -174,20 +174,21 @@ module Admin
end
def conference_wide_screen
#To display sponsors in the conference wide information page
# To display sponsors in the conference wide information page
@conference = Conference.find_by(short_title: params[:id])
@sponsors = @conference.sponsors
@program = @conference.program
@current_events = @conference.program.events.confirmed.select{ |event| event.is_current?}
@tweets = twitter_client.search_tweets(3, @conference.contact.social_tag)
@current_events = @conference.program.events.confirmed.select(&:current?)
@tweets = twitter_client.search_tweets(15, @conference.contact.social_tag)
respond_to do |format|
format.html{render layout: "conference_wide_screen"}
format.js {render :action=> "conference_wide_screen.js.haml"}
format.html{render layout: 'conference_wide_screen'}
format.js {render action: 'conference_wide_screen.js.haml'}
end
end
private
# To create a twitter client
def twitter_client
@twitter_client ||= TwitterWrapper.new

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

View file

@ -1,21 +1,16 @@
#main-display
- if @conference.present?
%section#main-heading
.container
.row
.col-md-12.text-center
%h1
= @conference.title
- if @conference.description.present?
%h3
= @conference.description
- if @conference.present?
.row
.col-md-12.text-center
%h1
= @conference.title
- if @conference.description.present?
%h3
= @conference.description
- if @program.present?
%section#event-display
.row
= render 'current_events'
- if @conference.contact.social_tag.present?
%section#tweets-display
- if @tweets.present?
= render 'conference_tweets'
- if @conference.contact.social_tag.present? && @tweets.present?
.row
= render 'conference_tweets'
- if @sponsors.any?
%section#sponsor-display
= render 'sponsors'
= render 'sponsors'