加群配置使用前端指令完成,方便管理。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import pymysql
|
||||
import dateparser
|
||||
import schedule
|
||||
import json
|
||||
from task.message_task_json import message_task_json
|
||||
|
||||
# 配置数据库连接
|
||||
db_config = {
|
||||
@@ -17,12 +18,6 @@ def get_db_connection():
|
||||
return connection
|
||||
|
||||
|
||||
# 解析自然语言时间
|
||||
def parse_natural_language_time(text):
|
||||
parsed_time = dateparser.parse(text)
|
||||
return parsed_time
|
||||
|
||||
|
||||
# 插入任务到数据库
|
||||
def insert_task_to_db(description, reminder_time, task_type):
|
||||
connection = get_db_connection()
|
||||
@@ -69,14 +64,20 @@ def schedule_recurring_task(reminder_time, task_id):
|
||||
|
||||
# 处理用户输入
|
||||
def handle_user_input(user_input, task_type):
|
||||
parsed_time = parse_natural_language_time(user_input)
|
||||
print(parsed_time)
|
||||
if parsed_time:
|
||||
formatted_time = parsed_time.strftime('%H:%M')
|
||||
print(f"Scheduling task for {formatted_time}")
|
||||
task_json = message_task_json(user_input)
|
||||
print(task_json)
|
||||
if task_json:
|
||||
|
||||
# 将JSON字符串解析为字典
|
||||
data = json.loads(task_json)
|
||||
|
||||
# 提取内容
|
||||
task = data["task"]
|
||||
reminder_time = data["reminder_time"]
|
||||
reason = data["reason"]
|
||||
|
||||
# 将任务存入数据库
|
||||
insert_task_to_db(user_input, formatted_time, task_type)
|
||||
insert_task_to_db(user_input, reminder_time, task_type)
|
||||
|
||||
# 获取插入的任务ID
|
||||
connection = get_db_connection()
|
||||
@@ -88,9 +89,9 @@ def handle_user_input(user_input, task_type):
|
||||
connection.close()
|
||||
# 根据任务类型调度任务
|
||||
if task_type == 'single':
|
||||
schedule_single_task(formatted_time, task_id)
|
||||
schedule_single_task(reminder_time, task_id)
|
||||
elif task_type == 'recurring':
|
||||
schedule_recurring_task(formatted_time, task_id)
|
||||
schedule_recurring_task(reminder_time, task_id)
|
||||
|
||||
|
||||
# 查询指定类型的任务
|
||||
@@ -152,6 +153,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# main()
|
||||
parsed_time = dateparser.parse('每天上午9:00提醒我开会', settings={'TIMEZONE': 'Asia/Shanghai'},)
|
||||
print(parsed_time)
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user