Created
July 5, 2013 18:53
-
-
Save bjacobel/5936500 to your computer and use it in GitHub Desktop.
Convert a newline-separated list of Twitter @Handles to Twitter IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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