如何解决Python Tweepy 取消关注最近的
我正在编写 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()
解决方法
由于推特按时间顺序显示好友列表,最近关注的将排在最前面。
所以我使用的技巧是将朋友列表反转为:
for friend in friends[::-1]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。