【问题标题】:Twython: Get a list of all your followers except those who are on your muted list?Twython:获取所有关注者的列表,除了那些在你的静音列表中的人?
【发布时间】:2015-07-26 22:36:09
【问题描述】:

我有这段代码可以使用 Twython 吸引我的 Twitter 关注者。我将如何修改它来代替:

“获取所有未出现在静音关注者列表中的 Twitter 关注者”?

我尝试了两次请求,一次针对关注者,一次针对 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))

【问题讨论】:

    标签: python python-2.7 twitter twython


    【解决方案1】:

    好的。找到了一种方法来做到这一点,但它并不优雅。它有效。我只是制作了不同的光标以传递给不同的循环。但是可能有更好的方法可以做到这一点,所以请随时在这里发表评论。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 2013-02-02
      • 2016-10-20
      • 2023-03-16
      • 2019-02-26
      • 1970-01-01
      • 2017-09-23
      相关资源
      最近更新 更多