我正在自学python,并且正在对其他人编写的机器人进行一些更改。
我正在尝试为 NSFW 或不适合儿童的单词添加过滤器。我已将这些词添加到名为 config.banned_name_keywords 的列表中。
我最初通过返回整个推文使其正常工作,但我试图返回找到的特定单词,以便我可以排除故障并编辑列表。
我可以使用 tweet.text 返回整个推文,但这会影响输出并阻塞屏幕。
我也试过 print(x) 但我不知道它是在哪里定义的。它首先返回找到推文的单词。
for tweet in searched_tweets:
if any(rtwords in tweet.text.lower().split() for rtwords in config.retweet_tags):
# The script only cares about contests that require retweeting. It would be very weird to not have to
# retweet anything; that usually means that there's a link you gotta open and then fill up a form.
# This clause checks if the text contains any retweet_tags
if tweet.retweeted_status is not None:
# In case it is a retweet, we switch to the original one
if any(y in tweet.retweeted_status.text.lower().split() for y in config.retweet_tags):
tweet = tweet.retweeted_status
else:
continue
if tweet.user.screen_name.lower() in config.banned_users or any(x in tweet.user.name.lower() for x in config.banned_name_keywords):
# If it's the original one, we check if the author is banned
print("Avoided user with ID: " + tweet.user.screen_name + " & Name: " + tweet.user.name)
continue
elif any(z in tweet.text.lower().split() for z in config.banned_name_keywords):
# If the author isn't banned, we check for words we don't want
print("Avoided tweet with words:" + z)
continue
犯罪嫌疑人X
互换的青春
相关分类