Guest User

Untitled

a guest
Dec 8th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. require 'rubygems'
  2. require 'tweetstream'
  3. require 'twitter'
  4. require 'yaml'
  5. require 'date'
  6. require 'time'
  7. require 'twilio-ruby'
  8. require 'redis'
  9.  
  10. config = YAML.load_file('config.yaml')
  11.  
  12. uri = URI.parse(config['redis_url'])
  13. REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
  14.  
  15. # set up a client to talk to the Twilio REST API
  16. twilio = Twilio::REST::Client.new config['account_sid'], config['auth_token'];
  17.  
  18. follow_users = Array[Twitter.user(config['username_to_follow']).id];
  19.  
  20. TweetStream.configure do |c|
  21. c.username = config['username']
  22. c.password = config['password']
  23. c.auth_method = :basic
  24. c.parser = :yajl
  25. end
  26.  
  27. client = TweetStream::Client.new()
  28.  
  29. client.on_error do |message|
  30. puts "Error received #{message}"
  31. end
  32.  
  33. params = Hash.new;
  34. params[:follow] = follow_users;
  35.  
  36. client.filter(params) do |status|
  37. if (!status.text.start_with? "RT")
  38. if (status.text.include? "#talk") || (status.text.include? "#hack" ) || (status.text.include? "#bof" )
  39. sms_followers = REDIS.smembers "sms_followers"
  40. for sms in sms_followers do
  41. twilio.account.sms.messages.create(
  42. :from => config['from_number'],
  43. :to => sms,
  44. :body => status.text
  45. )
  46. end
  47. end
  48. end
  49. puts "#{status.text} - #{status.created_at}"
  50. end
Add Comment
Please, Sign In to add comment