Bu konuda yardıma ihtiyacım var:
Bu kodu python'da oluşturdum, ancak tekrarlanan bazı adımlar olduğu için onu iyileştirmenin ve kısaltmanın bir yolunu bulamıyorum. Şimdiye kadar elde ettiğim şey bu. Yapmaya çalıştığım şey, önce erken benimseyenler listesinin takipçilerini almak, ardından takipçilerin takipçilerini almak ve aynı adımı üç kez daha yapmak.
Kod:
early_adopters = ['user_ID_1', 'user_ID_2']
users_follower = [] # list of every followers from early adopters
follower_list = [] # list of pairs of users (early_apdoter, follower)
for usr in early_adopters:
for user in tweepy.Cursor(api.followers, user_id = usr).items(3):
if user.id not in early_adopters:
users_follower.append(user.id_str)
follower_list.append((usr,user.id_str))
users_follower_S1 = random.choices(users_follower, k=3) # sample of user from the first surface follower_list_search
follower_list_1 = [] #list of pair of followers of followers
s2_follower_list = [] # list of pairs of users (early_apdoter, follower)
for usr_s1 in users_follower_S1:
for user in tweepy.Cursor(api.followers, user_id = usr_s1).items(3):
if user.id_str not in follower_list and usr_s1 not in early_adopters:
follower_list_1.append(user.id_str)
s2_follower_list.append((usr_s1, user.id_str))
users_follower_S2 = random.choices(follower_list_1, k=3) # Repeat the same process above but for the second surface
follower_list_2 = []
s3_follower_list = []
for usr_s2 in users_follower_S2:
for user in tweepy.Cursor(api.followers, user_id = usr_s2).items(3):
if user.id_str not in follower_list and usr_s2 not in early_adopters:
follower_list_2.append(user.id_str)
s3_follower_list.append((usr_s2, user.id_str))
users_follower_S3 = random.choices(follower_list_2, k=3) # Repeat the same process above but for the second surface
follower_list_3 = []
s4_follower_list = []
for usr_s3 in users_follower_S3:
for user in tweepy.Cursor(api.followers, user_id = usr_s3).items(3):
if user.id_str not in follower_list and usr_s3 not in early_adopters:
follower_list_3.append(user.id_str)
s4_follower_list.append((usr_s3, user.id_str))
Şimdiden teşekkürler!!
Bookmarks