Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created August 17, 2012 11:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/3378227 to your computer and use it in GitHub Desktop.
Save peterhellberg/3378227 to your computer and use it in GitHub Desktop.
Find your Twitter friends on Alpha (app.net)
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)
@peterhellberg
Copy link
Author

Run:

$ ruby twitter_friends_on_alpha.rb your_twitter_username

This will output a list of your Twitter friends that have the same username on Alpha.

@peterhellberg
Copy link
Author

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