Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A small script to list which of the people you follow are visible in public twitter autocomplete searches.
#!/usr/bin/ruby
# This script tells you which of your friends (people you follow) are
# auto-completable in public twitter user searches, e.g. by typing
# @username" into the search box. It takes four arguments for twitter
# API credentials: consumer_key, consumer_secret, access_token, and
# access_token_secret. You can create an twitter API app at
# https://developer.twitter.com/.
# Output is a tab-separated list of accounts, one per line, where the
# fields are: visible-in-search, screen name, display name, description.
#
# For instance:
#
# false mancsbondage That guy in Manchester who does stuff with rope...
# true anarcho_slut 🌹june amelia rose🌹 anarchist leatherdyke fiction
require 'net/http'
require 'json'
require 'pp'
require 'twitter'
def findable_user? user
acct = user.screen_name
json = Net::HTTP.get(URI("https://twitter.com/i/search/typeahead.json?count=10&filters=false&q=%40#{acct}&result_type=topics%2Cusers&src=SEARCH_BOX"))
x = JSON.parse(json)
if x["users"].map { |u| u["screen_name"] }.find { |sn| sn == acct }
true
else
false
end
end
def client
consumer_key, consumer_secret, access_token, access_token_secret = ARGV
Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key
config.consumer_secret = consumer_secret
config.access_token = access_token
config.access_token_secret = access_token_secret
end
end
# How many users can we fetch in a single call?
USERS_REQ_LIMIT = 100
# Convert a collection of ids to full users.
def user_ids_to_users(c, ids)
users = {}
ids.each_slice(USERS_REQ_LIMIT) do |chunk|
c.users(chunk).each do |user|
users[user.id] = user
end
end
ids.map do |id|
users[id]
end
end
def user_friends(c, user)
user_ids_to_users(c, c.friend_ids.to_a)
end
c = client
u = client.user
user_friends(c, u).each do |u|
desc = u.description.gsub(/\n/, ' ')
puts "#{findable_user? u}\t#{u.screen_name}\t#{u.name}\t#{desc}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.