Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created February 27, 2014 10:21
Show Gist options
  • Save emad-elsaid/9247639 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9247639 to your computer and use it in GitHub Desktop.
create a thanks for following me twitter bot using ruby
#!/usr/bin/env ruby
require 'Twitter'
# Create a read write application from :
# https://apps.twitter.com
# authenticate it for your account
# fill in the following
config = {consumer_key: '', consumer_secret: '',
access_token: '', access_token_secret: ''}
me = 'Blaze Boy' # to prevent DM yourself
Thread.new do
loop do
begin
rClient = Twitter::REST::Client.new config
sClient = Twitter::Streaming::Client.new(config)
sClient.user do |object|
if object.is_a? Twitter::Streaming::Event and object.name==:follow
user = object.source
if user.name != me
rClient.create_direct_message user, "Thanks for following me #{user.name} :)"
puts "New follower : #{object.source.name}"
end
end
end
rescue
puts 'error occurred, sleeping for 5 seconds'
sleep 5
end
end
end
loop { sleep 5 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment