我有这个代码块,可以让我的Twitter粉丝使用Twython。我将如何修改它来代替:
“让你的所有推特粉丝都没有出现在你柔和的粉丝列表中”?
我尝试过两次请求,一次是关注者,另一次是twitter.list_mutes,然后将两个列表作为集合进行比较。但twitter api对此并不太满意。
连连呢?
followers = []
next_cursor = -1
while(next_cursor):
get_followers = twitter.get_followers_list(screen_name=username, count=200, cursor=next_cursor)
for follower in get_followers["users"]:
followers.append(follower["screen_name"].encode("utf-8"))
next_cursor = get_followers["next_cursor"]
print "%s followers found" % str(len(followers))
答案 0 :(得分:0)
好的。找到了办法,但它并不优雅。它起作用。我只是将不同的光标传递给另一个循环。然而,有可能更好的方法来做到这一点,所以请随时在这里发表评论。
https://github.com/sharkwheels/twitter_muter/blob/master/randoMute.py
### GET FOLLOWERS ##################
while(next_cursor):
get_followers = twitter.get_followers_list(screen_name=username, count=200, cursor=next_cursor)
for follower in get_followers["users"]:
followers.append(follower["screen_name"].encode("utf-8"))
next_cursor = get_followers["next_cursor"]
print "%s followers found" % str(len(followers))
print " "
print "get muted users"
## GET ALREADY MUTED FOLLOWERS ##################
while(butts_cursor):
get_muted = twitter.list_mutes(screen_name=username, count=200, cursor=butts_cursor)
for x in get_muted["users"]:
silent_followers.append(x["screen_name"].encode("utf-8"))
butts_cursor = get_muted["next_cursor"]
print " "
print "%s silent_followers found" % str(len(silent_followers))
print silent_followers