Created
August 19, 2020 10:50
-
-
Save DipanshKhandelwal/92e3d51531e3e01a14fa51bd50eec6ff to your computer and use it in GitHub Desktop.
Scraping Verified Twitter Usernames
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
import oauth2 as oauth | |
import json | |
import random | |
import time | |
# You can add as many keys as you want here !! :) | |
keys = { | |
"key1": { | |
"CONSUMER_KEY": "", | |
"CONSUMER_SECRET": "", | |
"ACCESS_TOKEN": "", | |
"ACCESS_SECRET": "", | |
}, | |
"key2": { | |
"CONSUMER_KEY": "", | |
"CONSUMER_SECRET": "", | |
"ACCESS_TOKEN": "", | |
"ACCESS_SECRET": "", | |
}, | |
# ... | |
} | |
users = keys.keys() | |
USER_NAME = "verified" | |
fileToSave = open('twitter_verified_usernames.txt', 'w+') | |
timeline_endpoint = "https://api.twitter.com/1.1/friends/list.json?screen_name=verified" | |
cursor = '0' | |
for _ in range(300): | |
for i in keys: | |
user = keys[i] | |
consumer = oauth.Consumer( | |
key=user["CONSUMER_KEY"], secret=user["CONSUMER_SECRET"]) | |
access_token = oauth.Token( | |
key=user["ACCESS_TOKEN"], secret=user["ACCESS_SECRET"]) | |
client = oauth.Client(consumer, access_token) | |
print("Consumer Key ", user["CONSUMER_KEY"]) | |
print("Consumer Secret", user["CONSUMER_SECRET"]) | |
print("Access Token ", user["ACCESS_TOKEN"]) | |
print("Access Secret ", user["ACCESS_SECRET"]) | |
while True: | |
response, data = client.request(timeline_endpoint) | |
data = json.loads(data) | |
print(response['status']) | |
if(response["status"] == '200'): | |
for k in data["users"]: | |
print(k["screen_name"]) | |
fileToSave.write(k["screen_name"]+'\n') | |
cursor = data["next_cursor_str"] | |
timeline_endpoint = "https://api.twitter.com/1.1/friends/list.json?screen_name=verified&cursor="+cursor | |
else: | |
break | |
time.sleep(15*60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment