Tweepy unfollow函数仅取消最近的跟踪?

2024-10-02 16:22:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在编写一个Twitter python脚本,它一次可以释放10个人的关注度,它很有效,但它只是释放了我最近关注的账户。我需要改变这一点,使之不跟随我之前跟踪时间最长的帐户

def unfollow(): 

    friendNames, followNames = [], []
    try:
        for friend in tweepy.Cursor(api.friends).items(10):
            friendNames.append(friend.screen_name)

        for follower in tweepy.Cursor(api.followers).items(10):
            followNames.append(follower.screen_name)
    
    except tweepy.RateLimitError:
        print("You're getting an error")

    friendset = set(friendNames)
    followset = set(followNames)
    not_fback = friendset.difference(followset)
    for not_following in not_fback:
        api.destroy_friendship(not_following)
        print("Unfollowing: " + not_following)

unfollow()

Tags: nameinfriendapifornotitemsscreen