试图找出一种方法,让我的Twitter机器人根据请求的日期向用户发推文



>我已经设法让我的机器人解析它的提及,以正确请求日期的方法。例如,如果用户使用"提醒 09/20/2019"或任何其他随机日期提及我的机器人,它将响应"日期测试成功"。

我目前遇到的问题是我希望我的机器人只在请求的日期回复提及。例如,如果用户使用"提醒 10/1/2019"提及我的机器人,我希望我的机器人在 2019 年 10 月 1 日使用"日期测试成功"进行响应。

如果我的问题解释得不够清楚,我可以更深入地解释。

我目前正在使用的代码在这里:

> # Extended tweet mode is for showing longer tweets in mentions
mentions = api.mentions_timeline(tweet_mode='extended')
for tweets in reversed(mentions):
date_search_match = re.compile(r"(?:reminder|Reminder)sd{2}/d{2}/d{4}")
if date_search_match.search(tweets.full_text)
api.update_status(f"@{tweets.user.screen_name} Date Test Successful")

您可以将日期存储在数据库中,然后每天使用 python 调度包查询一次提醒,如下所示:github.com/dbader/schedule 。

例如:

import schedule
import time
def job():
print("I'm searching the DB for today's reminders...")
<logic for querying the DB>
print("and tweeting out the reminders...")
<logic for tweeting the reminders with tweepy>
schedule.every().day.at("10:30").do(job)
while True:
schedule.run_pending()
time.sleep(1)

或者,您可以在cron作业上运行 python 脚本。

最新更新