Tweepy Bot无法过滤用户

时间:2019-06-27 02:49:14

标签: python twitter bots tweepy

为什么我的漫游器从被禁止的用户列表中转发用户的推文? 它应该过滤掉禁止用户列表中用户的任何推文,并防止使用禁止词列表中的单词进行推文,但出于某些原因,它不会这么做

bannedwords = ["vote", "bot", "b0t", "tag" , "#teenchoice", "onlyfans"]
bannedusers = ["ProductReviewMY", "followandrt2win", 'b0t', 'bottybotbotl','bot', 'spot', 'lvbroadcasting', 'jflessauSpam', 'bryster125', 'MobileTekReview', 'ilove70315673', 'traunte', 'ericsonabby', '_aekkaphon'] # does not need to be the entire username! you can just put 'bot' for names like 'b0tspotter', etc.


twitter_client = API(auth)
friends = api.friends_ids(SCREEN_NAME)


def search(i):
    if i.id > 1141668107372638208 : 
        if any(k in i.text.lower() for k in keywords) and any(k in i.text.lower() for k in secondaryWords) and not any(k in i.text.lower() for k in bannedwords):
            if not any(k in i.author.screen_name.lower().replace("0", "o") for k in bannedusers):
                    if not i.retweeted:
                        try:
                            api.retweet(i.id)
                            print("rt " + (i.text))

                            if "follow" in i.text or "#follow" in i.text or "Follow" in i.text or "#Follow" in i.text or "FOLLOW" in i.text or "#FOLLOW" in i.text or "following" in i.text or "#following" in i.text or "FOLLOWING" in i.text or "#FOLLOWING" or "Following" in i.text or "#Following" in i.text:

                            user_id = i.retweeted_status.user.id
                            api.create_friendship(user_id)

                        except Exception:
                            pass



class MyStreamListener(StreamListener):


    def on_status(self, data):
        search(data) 
        return True

if __name__ == '__main__':
    listener = MyStreamListener()
    stream = Stream(auth, listener)
    stream.filter(track=keywords)

0 个答案:

没有答案