Skip to content

Instantly share code, notes, and snippets.

@bjacobel
Created July 5, 2013 18:53
Show Gist options
  • Save bjacobel/5936500 to your computer and use it in GitHub Desktop.
Save bjacobel/5936500 to your computer and use it in GitHub Desktop.
Convert a newline-separated list of Twitter @Handles to Twitter IDs
from twitter import Twitter, OAuth
import time
oauth = {
'OAUTH_TOKEN': '',
'OAUTH_SECRET': '',
'CONSUMER_KEY': '',
'CONSUMER_SECRET': '',
}
twitter = Twitter(auth=OAuth(oauth['OAUTH_TOKEN'], oauth['OAUTH_SECRET'], oauth['CONSUMER_KEY'], oauth['CONSUMER_SECRET']))
users = [line.strip() for line in open("users.txt").readlines()]
ids = open('ids.txt', 'w')
for user in users:
id = str(twitter.users.lookup(screen_name=user)[0]['id'])
print user + " has an ID of " + id
ids.write(id + "\n")
# time.sleep(1) # Optional: to combat API rate-limiting for large lists
ids.write("\b")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment