Created
August 17, 2012 11:43
-
-
Save peterhellberg/3378227 to your computer and use it in GitHub Desktop.
Find your Twitter friends on Alpha (app.net)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'open-uri' | |
require 'json' | |
screen_name = ARGV[0] | |
if screen_name.nil? | |
puts "ruby twitter_friends_on_alpha.rb twitter_username" | |
exit | |
end | |
def twitter_friends(twitter_username) | |
base_uri = "https://api.twitter.com/1/users/lookup.json?user_id=" | |
twitter_friend_ids(twitter_username). | |
each_slice(60).each_with_object([]) { |ids_chunk, screen_names| | |
screen_names << get_json(base_uri + ids_chunk.join(',')).map { |h| | |
h.fetch('screen_name').downcase | |
} | |
}.flatten | |
end | |
def twitter_friend_ids(twitter_username) | |
base_uri = "https://api.twitter.com/1/friends/ids.json?id=" | |
get_json(base_uri + twitter_username)['ids'] | |
end | |
def get_json(url) | |
JSON.parse open(url).read | |
end | |
def twitter_friends_on_alpha(screen_name) | |
http = Net::HTTP.new('alpha.app.net', 443) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
twitter_friends(screen_name).each_with_object([]) { |username, alpha_users| | |
if http.request_head("/#{username}").code == "200" | |
puts username | |
end | |
} | |
end | |
twitter_friends_on_alpha(screen_name) |
You can also use http://friendfind.co/
(It will also find friends that have a new username on http://alpha.app.net/)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run:
This will output a list of your Twitter friends that have the same username on Alpha.