Skip to content

Instantly share code, notes, and snippets.

@rgov
Last active December 16, 2015 19:49
Show Gist options
  • Select an option

  • Save rgov/5487616 to your computer and use it in GitHub Desktop.

Select an option

Save rgov/5487616 to your computer and use it in GitHub Desktop.
Hastily-written set intersection of a Twitter user's followed and follower lists.
#!/usr/bin/env python
# Uses the python twitter tools library: http://mike.verdone.ca/twitter/
from twitter import *
import os, sys, time
# Hm what is this? https://gist.github.com/rhenium/3878505
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
def get_user_list(func, name):
users, cursor = set(), -1
while cursor != 0:
result = func(
screen_name=name,
cursor=cursor,
skip_status=True,
include_user_entities=False)
cursor = result['next_cursor']
try:
for u in result['users']:
users.add(u['screen_name'])
finally:
pass
# To prevent rate limiting
time.sleep(10)
return users
if __name__ == '__main__':
oauth_file = os.path.expanduser('~/.twitter_oauth')
if not os.path.exists(oauth_file):
oauth_dance("App", CONSUMER_KEY, CONSUMER_SECRET, oauth_file)
oauth_token, oauth_token_secret = read_token_file(oauth_file)
t = Twitter(
auth=OAuth(
oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET),
secure=True,
api_version='1.1',
domain='api.twitter.com')
friends = get_user_list(t.friends.list, sys.argv[1])
followers = get_user_list(t.followers.list, sys.argv[1])
print friends & followers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment