尝试使用Tweepy创建一个Twitter机器人,该机器人将在提及时提醒用户有关Tweet的信息

时间:2019-06-01 02:34:36

标签: python tweepy

如标题所述,我正在尝试创建一个Twitter机器人,以提醒用户有关其所请求的特定日期或时间的推文。

我知道我必须使用datetime库,我的问题是我不太熟悉该库,无法将信息解析为timedelta等。

代码如下:

def reply_to_tweets():
    """Replies to users who mention the user with date requested"""
    print('Searching through mentions...')
    last_seen_id = retrieve_last_seen_id(name_of_file)
    # Extended tweet mode is to show longer tweets in mentions
    mentions = api.mentions_timeline(last_seen_id, tweet_mode='extended')
    date_or_time = # ???
    for mention in reversed(mentions):
        if '!Memorize ' + date_or_time in mention.full_text:
            print('Found tweet...\n' + 'MENTION ID: ' + str(mention.id))
            print('Replying back to tweet...')
            api.update_status('@{} Will remind you of this tweet on the date or time requested.'.
                              format(mention.user.screen_name))
            if date_or_time:
                api.update_status("@{} Remember this tweet? "
                                  + date_or_time.format(mention.user.screen_name))
                last_seen_id = mention.id
                store_last_seen_id(last_seen_id, name_of_file)

0 个答案:

没有答案