Skip to content

Instantly share code, notes, and snippets.

@afeld
Last active April 12, 2019 06:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save afeld/5589756 to your computer and use it in GitHub Desktop.
Save afeld/5589756 to your computer and use it in GitHub Desktop.
Twitter bio search

A friend is looking for a new tech job and asked if I knew anyone at a handful of companies. I'm (meaningfully) connected to more people who are relevant to this on Twitter than LinkedIn, so figured it would be easiest to scour people's bios. Naturally, I did this in the nerdiest way possible and automated it.

<3 @aidanfeldman

P.S. See also:

# usage:
#
# $ gem install t twitter
# $ t authorize
# $ ruby twitter_bio_search.rb
# from XXX peeps:
#
# LEVO
# name - @screen_name - bio
# ...
require 'yaml'
require 'twitter'
# created via 't' gem CLI
# just grab first authentication
AUTH_INFO = YAML.load_file('/Users/afeld/.trc')['profiles'].values[0].values[0]
client = Twitter::REST::Client.new do |config|
config.consumer_key = AUTH_INFO['consumer_key']
config.consumer_secret = AUTH_INFO['consumer_secret']
config.access_token = AUTH_INFO['token']
config.access_token_secret = AUTH_INFO['secret']
end
# gather followers + following
all_ids = Set.new
client.follower_ids.each do |follower_id|
all_ids << follower_id
end
client.friend_ids.each do |following_id|
all_ids << following_id
end
puts "from #{all_ids.size} peeps:\n\n"
TERM_REGEX = /birchbox|bonobos|codecademy|etsy|foursquare|gilt|google|levo|okcupid|seamless|spotify|squarespace|streeteasy|tumblr|vimeo|warby/i
users_by_terms = {}
# can only retrieve 100 at a time
all_ids.each_slice(100) do |some_ids|
client.users(*some_ids, include_entities: false).each do |user|
desc = user.description
if desc
desc.scan(TERM_REGEX) do |term|
term = term.downcase
users_by_terms[term] ||= Set.new
users_by_terms[term] << user
end
end
end
end
users_by_terms.sort.each do |term, users|
puts term.upcase
users.each do |user|
desc = user.description
if desc
# compress whitespace
desc = desc.gsub(/\s+/, ' ')
end
puts "https://twitter.com/#{user.screen_name} – #{user.name} – #{desc}"
end
puts "\n"
end
@melodykramer
Copy link

was searching for how to do this. Of course it's from you.

@almereyda
Copy link

almereyda commented Jul 31, 2016

I have created a fork at https://gist.github.com/almereyda/e762a3d50c6818090c46ecad594dcadc which also searches the location field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment