例如,我正在创建一个类似Reddit的RemindMeBot的Twitter机器人(如果有人熟悉的话)。如果用户在推文中提及该机器人,则希望在30秒内用“!在30秒内记住”一句来提醒他们,我将如何在该时间范围内提醒他们?
这几乎是我想要获得的以下功能:
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 for showing longer tweets in mentions
mentions = api.mentions_timeline(last_seen_id, tweet_mode='extended')
target_date = datetime.datetime.strptime('%d/%m/%y %H:%M')
for mention in reversed(mentions):
if target_date in mention.full_text:
print('Found tweet!' + ' MENTION ID: ' + str(mention.id))
print('Replying back to tweet...')
if target_date:
api.update_status("@{} Here's your reminder.".format(mention.user.screen_name))
last_seen_id = mention.id
store_last_seen_id(last_seen_id, name_of_file)