forked from jefflinwood/twitter2twilio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tweeter-keeper.rb
54 lines (40 loc) · 1.27 KB
/
tweeter-keeper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'rubygems'
require 'tweetstream'
require 'twitter'
require 'yaml'
require 'date'
require 'time'
require 'twilio-ruby'
require 'redis'
uri = URI.parse("redis://redistogo:[email protected]:9800/")
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
config = YAML.load_file('config.yaml')
# set up a client to talk to the Twilio REST API
twilio = Twilio::REST::Client.new config['account_sid'], config['auth_token'];
follow_users = Array[Twitter.user(config['username_to_follow']).id];
sms_followers = Array['+15125690253','+15127910975'];
TweetStream.configure do |c|
c.username = config['username']
c.password = config['password']
c.auth_method = :basic
c.parser = :yajl
end
client = TweetStream::Client.new()
client.on_error do |message|
puts "Error received #{message}"
end
params = Hash.new;
params[:follow] = follow_users;
client.filter(params) do |status|
if status.text.include? "#talk" || status.text.include? "#hack"
sms_followers = REDIS.smembers "sms_followers"
for sms in sms_followers do
twilio.account.sms.messages.create(
:from => config['from_number'],
:to => sms,
:body => status.text
)
end
end
puts "#{status.text} - #{status.created_at}"
end