0

我目前想寻找一个关键字并返回该词的所有提及。不过,我只想要最后 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 作为日期时间,但我认为它不能正常工作,因为它在我的过滤器之前返回时间。他们无论如何都要约会吗?

4

1 回答 1

0

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

于 2021-04-28T14:25:32.037 回答