Python Tweepy 取消关注最近的

Python Tweepy Unfollow Least Recent

我正在开发 Python 和 Tweepy 脚本来取消关注未关注我的用户。下面的脚本正在运行,但它取消了我关注的最近用户的关注。我希望它取消关注最近最少的用户。我在网上看了一段时间,但什么也没找到。谁能帮我将这段代码添加到我的脚本中?谢谢!

import tweepy
import time

def get_twitter_api():
    # personal details
    consumer_key = "consumer_key"
    consumer_secret = "consumer_secret"
    access_token = "access_token"
    access_token_secret = "access_token_secret"

    # authentication of consumer key and secret
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

    # authentication of access token and secret
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True)
    return api

def process():
    interval = 60 * 2
    api = get_twitter_api()

    followers = api.followers_ids(api.me().id)
    print("Followers", len(followers))
    friends = api.friends_ids(api.me().id)
    print("You follow:", len(friends))


    for friend in friends:
        if friend not in followers:
            api.destroy_friendship(friend) 
            time.sleep(interval)

if __name__ == "__main__":
    process()

由于 twitter 按时间顺序显示好友列表,因此最近关注的人将排在最前面。

所以我使用的技巧是将好友列表反转为:

for friend in friends[::-1]