Advertisement
Guest User

twitter.rb

a guest
Jun 30th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.85 KB | None | 0 0
  1. require 'twitter'
  2.  
  3.  
  4. #### Get your twitter keys & secrets:
  5. #### https://dev.twitter.com/docs/auth/tokens-devtwittercom
  6. Twitter.configure do |config|
  7.   config.consumer_key = 'blahblahblah'
  8.   config.consumer_secret = 'blahblahblah'
  9.   config.oauth_token = 'blahblahblah'
  10.   config.oauth_token_secret = 'blahblahblah'
  11. end
  12.  
  13. search_term = URI::encode('@martynkeigher')
  14.  
  15. SCHEDULER.every '1m', :first_in => 0 do |job|
  16.   begin
  17.     tweets = Twitter.search("#{search_term}").results
  18.  
  19.     if tweets
  20.       tweets.map! do |tweet|
  21.         { name: tweet.user.name, body: tweet.text, avatar: tweet.user.profile_image_url_https }
  22.       end
  23.       send_event('twitter_mentions', comments: tweets)
  24.     end
  25.   rescue Twitter::Error
  26.     puts "\e[33mFor the twitter widget to work, you need to put in your twitter API keys in the jobs/twitter.rb file.\e[0m"
  27.   end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement