【问题标题】:Filter tweets by text with user_timeline in Tweepy在 Tweepy 中使用 user_timeline 按文本过滤推文
【发布时间】:2017-12-29 02:56:01
【问题描述】:

我正在尝试过滤从某个帐户获得的结果,我通过关键字“api.user_timeline”获得,所以基本上我希望程序忽略来自该帐户的推文,这些推文中没有该关键字推文,但我似乎无法找到解决方案。

import time

for tweet in tweepy.Cursor(api.user_timeline, since='2017-12-27',
                           screen_name='example').items(2):
    try:
        if not tweet.retweeted:
            tweet.retweet()
            m = "@example This is an example."
            t = api.update_status(status=m, in_reply_to_status_id=tweet.id)
            print("Example, Working...")
            time.sleep(5)
    except tweepy.TweepError as e:
        print(e.reason)
        time.sleep(5)
        break
    except StopIteration:
        break

会是:(?)

if not tweet.retweeted:
    if tweet.text == "keyword":
       doThis()

我真的不知道,所以非常感谢任何帮助!

【问题讨论】:

    标签: python api text twitter tweepy


    【解决方案1】:
    if not tweet.retweeted:
        if "keyword" in tweet.text:
            doThis()
    

    您可能还希望使用string.lower() 使此不区分大小写。

    【讨论】:

    • 你是救生员,非常感谢!!我搜索了整个 Tweepy 的文档和整个互联网,但我找不到任何解决方案! :)
    猜你喜欢
    • 2017-07-31
    • 1970-01-01
    • 2018-07-03
    • 2020-01-29
    • 2015-08-02
    • 2019-03-10
    • 2021-04-30
    • 2012-08-06
    • 1970-01-01
    相关资源
    最近更新 更多