SHARE
TWEET

Untitled

a guest May 27th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env ruby
  2. require 'rubygems'
  3. require 'tweetstream'
  4. require 'boxcar_api'
  5.  
  6. SETTINGS = {
  7.   :key          => 'xyz',          # Provider Key
  8.   :secret       => 'xyz',          # Provider Secret
  9.   :tweeter      => 'macrumorslive' # Whom we'll be following on Twitter
  10.   :tweeter_id   => 1581511,        # The tweeter's user id (check their RSS feed)
  11.   :twitter_user => 'xyz',          # The username for your Twitter account.
  12.   :twitter_pass => 'xyz'           # The password for your Twitter account.
  13. }
  14.  
  15. class ServerTrack
  16.  
  17.   def deliver_push_notification(status)
  18.     # Streaming Follow API gives us RTs, in_reply_to's etc. We just want original tweets from the tweeters account.
  19.     if status[:user][:screen_name].downcase == SETTINGS[:tweeter].downcase
  20.  
  21.       bp = BoxcarAPI::Provider.new(SETTINGS[:key], SETTINGS[:secret])
  22.       bp.broadcast(status[:text])
  23.  
  24.       $stderr.puts "*** Sent notification for #{status[:text]}"
  25.     end
  26.   end
  27.  
  28.   def run
  29.     $stderr.puts "Starting tweet provider for #{SETTINGS[:tweeter]}"
  30.  
  31.     TweetStream::Client.new(SETTINGS[:twitter_user], SETTINGS[:twitter_pass]).follow(SETTINGS[:tweeter_id]) do |status|
  32.       deliver_push_notification(status)
  33.     end
  34.   end
  35. end
  36.  
  37. st = ServerTrack.new
  38. st.run
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top