【问题标题】:How to get all tweets after a DateTime with Twitter API and Tweepy如何使用 Twitter API 和 Tweepy 在 DateTime 之后获取所有推文
【发布时间】:2021-04-28 14:11:38
【问题描述】:

我目前想查找一个关键字并返回该词的所有提及。不过,我只想要最后 15 分钟内的所有内容。我目前只知道如何发送日期而不是 DateTime。我的代码如下

def search_hash(api, since_id):
    logger.info("Retrieving tweets")
    search_words = "#keyword"
    date_since = "2021-04-28 13:48:01"
    new_since_id = since_id
    tweetss = tw.Cursor(api.search,
        q=search_words,
        result_type='latest',
        lang="en",
        count = 100,
        since=date_since,
        since_id=since_id).items()
    count = 0
    for tweet in tweetss:
        count = count + 1
        print(tweet.text)
        print(tweet.created_at)
        new_since_id = max(tweet.id, new_since_id)
    print(count)
    return new_since_id

我尝试使用 date_since 作为日期时间,但我认为它不能正常工作,因为它在我的过滤器之前返回时间。他们到底要不要约会?

【问题讨论】:

    标签: python twitter tweepy twitterapi-python


    【解决方案1】:

    我通过获取最新推文的 ID 然后使用该 ID 作为应检查的最后一个 ID 并让脚本每 15 分钟运行一次,同时每次更新 last_id 来解决这个问题

    【讨论】:

      猜你喜欢
      • 2016-06-29
      • 2011-12-27
      • 2014-10-23
      • 2021-12-31
      • 1970-01-01
      • 2015-10-08
      • 2023-03-31
      • 2015-03-31
      • 2017-02-11
      相关资源
      最近更新 更多