Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Created May 2, 2011 21:41
Show Gist options
  • Save ivanoats/952445 to your computer and use it in GitHub Desktop.
Save ivanoats/952445 to your computer and use it in GitHub Desktop.
Pick a random winner from range of @reply tweets
# ruby-1.9.2-p180
require 'twitter' #gem install twitter
require 'ap' #gem install awesome_print
Twitter.configure do |config|
config.consumer_key = 'top secret'
config.consumer_secret = 'top secret'
config.oauth_token = 'top secret'
config.oauth_token_secret = 'top secret'
end
# collect the tweets during the context. must know the first id and last id
contest_tweets = Twitter.mentions(:since_id => 59291047129387008, :max_id => 59717310998511616, :count => 150)
# sort the tweets by username
contest_tweets.sort do |a,b|
a.user.screen_name <=> b.user.screen_name
end
usernames = ["sustainableweb"]
no_dups = []
# reject any duplicate entries
contest_tweets.each do |t|
unless usernames.include? t.user.screen_name #(not in) usernames then
no_dups << t.user.screen_name
end
usernames << t.user.screen_name
end
# print out the tweets
# contest_tweets.each do |m|
# puts m.user.screen_name + " : " + m.text
# end
# print out names without duplicates
puts "-----------------------------------------\n"
no_dups2 = no_dups.sort {|a,b| a.downcase <=> b.downcase}
no_dups2.each do |m|
ap m
end
#select a winner
winner = no_dups[rand(no_dups.size)]
winner2 = no_dups[rand(no_dups.size)]
puts "-----------------------------------------\n"
puts "winner #1 is:"
puts winner
puts "winner #2 is:"
puts winner2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment