Created
October 14, 2020 08:49
-
-
Save vessaldaneshvar/6e5248301eb1b11b8d2b50ccf3668159 to your computer and use it in GitHub Desktop.
get follower of celebrity Person
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 MySQLdb | |
import tweepy | |
import json | |
import time | |
import sys | |
with open("token_list.json") as fp: | |
data = json.load(fp) | |
# Connect to MySQL | |
db = MySQLdb.connect(host="localhost",user="user",passwd="password",db="dbname",charset="utf8mb4") | |
cursor = db.cursor() | |
token_index = int(sys.argv[1]) | |
consumer_key = data['listtoken'][token_index]["consumer_key"] | |
consumer_secret = data['listtoken'][token_index]["consumer_secret"] | |
access_token = data['listtoken'][token_index]["access_token"] | |
access_token_secret = data['listtoken'][token_index]["access_token_secret"] | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token,access_token_secret) | |
api = tweepy.API(auth,wait_on_rate_limit_notify=True,wait_on_rate_limit=True) | |
while True: | |
cursor.execute("select userids from get_follower where state='notget'") | |
row = cursor.fetchone() | |
if not row : | |
break | |
cursor.execute("update get_follower set state='getting' where userids=%s;",[row[0]]) | |
db.commit() | |
print(f"STARTED::{row[0]}") | |
try: | |
for follower in tweepy.Cursor(api.followers_ids,user_id=f"{row[0]}").items(): | |
try: | |
cursor.execute("INSERT INTO followerlist(mainuser,followeruser) values (%s,%s);",(row[0],follower)) | |
except Exception as e: | |
print(e) | |
db.commit() | |
cursor.execute("update get_follower set state='done' where userids=%s;",[row[0]]) | |
db.commit() | |
except Exception as e: | |
cursor.execute("update get_follower set state='NOT_IDS' where userids= %s;",[row[0]]) | |
db.commit() | |
print(e) | |
continue | |
db.commit() | |
cursor.close() | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment