2022-04-17 22:36:19 +08:00
|
|
|
|
import os
|
|
|
|
|
import uuid
|
|
|
|
|
import json
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
from utils import BasicUtils
|
2022-04-19 20:18:10 +08:00
|
|
|
|
|
2022-04-17 22:36:19 +08:00
|
|
|
|
"""
|
|
|
|
|
todo : 暂时创建单个文件存储该列表下所有待办事项,文件命名为 {uuid}.otl
|
|
|
|
|
同级还有 library.json 存储该列表信息
|
|
|
|
|
上一级创建一个配置文件,里边保存“我的一天”、“重要” 的 列表uuid/待办事项uuid
|
|
|
|
|
始终还是要读取文件,选择尽量少的读取和写入
|
|
|
|
|
(可以尝试在待办事项添加 isMyDay属性和isImportant属性)
|
|
|
|
|
"""
|
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
# class CreateToDo:
|
|
|
|
|
"""
|
|
|
|
|
:param item_type: 创建的类型,为ToDo和ToDoList
|
|
|
|
|
:param name: 要创建的ToDoList名字
|
|
|
|
|
:param todo_list_uid : 待办事项列表的uid,可选
|
|
|
|
|
"""
|
|
|
|
|
|
2022-04-17 22:36:19 +08:00
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
def CreateToDo(item_type, name, todo_list_uid=None):
|
|
|
|
|
uid = str(uuid.uuid4())
|
|
|
|
|
config_path = BasicUtils.return_work_dir()
|
|
|
|
|
todo_list_path = config_path + 'ToDoList/'
|
|
|
|
|
if not os.path.exists(todo_list_path):
|
|
|
|
|
os.mkdir(todo_list_path)
|
|
|
|
|
default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
2022-04-22 22:09:38 +08:00
|
|
|
|
print('<CreateToDo>'+uid)
|
2022-04-20 22:48:23 +08:00
|
|
|
|
if item_type == 'ToDoList':
|
|
|
|
|
# print(item_type)
|
|
|
|
|
try:
|
|
|
|
|
"""
|
|
|
|
|
createdAt : 创建时间
|
|
|
|
|
dueTo : 完成时间
|
|
|
|
|
itemType : 类型
|
|
|
|
|
notes : 笔记
|
|
|
|
|
title : 标题
|
|
|
|
|
updatedAt : 最后一次更新时间
|
|
|
|
|
"""
|
|
|
|
|
# os.mkdir(todo_list_path)
|
|
|
|
|
out_config = {
|
|
|
|
|
"createdAt": default_time,
|
|
|
|
|
"dueTo": '',
|
|
|
|
|
"itemType": item_type,
|
|
|
|
|
"notes": "",
|
|
|
|
|
"title": name,
|
|
|
|
|
"uid": uid,
|
2022-04-22 22:09:38 +08:00
|
|
|
|
"Theme": '0',
|
2022-04-20 22:48:23 +08:00
|
|
|
|
"updatedAt": default_time
|
|
|
|
|
}
|
|
|
|
|
# library = {
|
|
|
|
|
# "title": name,
|
|
|
|
|
# "uid": uid
|
|
|
|
|
# }
|
|
|
|
|
with open(todo_list_path + '{' + uid + '}.otl', 'w') as f:
|
|
|
|
|
f.write(json.dumps(out_config, indent=4, ensure_ascii=False))
|
|
|
|
|
# json.dump(out_config, f)
|
|
|
|
|
return uid
|
|
|
|
|
except IOError as e:
|
|
|
|
|
print(e)
|
|
|
|
|
return False
|
2022-04-22 22:09:38 +08:00
|
|
|
|
elif item_type == 'Todo':
|
2022-04-20 22:48:23 +08:00
|
|
|
|
try:
|
|
|
|
|
# done : 完成状态
|
|
|
|
|
# todoListUid : 父列表id
|
|
|
|
|
out_config = {
|
|
|
|
|
"createdAt": default_time,
|
|
|
|
|
"done": False,
|
|
|
|
|
"dueTo": '',
|
2022-04-22 22:09:38 +08:00
|
|
|
|
"itemType": item_type,
|
2022-04-20 22:48:23 +08:00
|
|
|
|
"notes": "",
|
|
|
|
|
"isMyDay": False,
|
|
|
|
|
"isImportant": False,
|
|
|
|
|
"title": name,
|
|
|
|
|
"todoListUid": todo_list_uid,
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"updatedAt": default_time
|
|
|
|
|
}
|
|
|
|
|
with open(todo_list_path + '{' + uid + '}.otl', 'w') as f:
|
|
|
|
|
f.write(json.dumps(out_config, indent=4, ensure_ascii=False))
|
|
|
|
|
return uid
|
2022-04-17 22:36:19 +08:00
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
except IOError as e:
|
|
|
|
|
print(e)
|
|
|
|
|
return False
|
2022-04-17 22:36:19 +08:00
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
#
|
|
|
|
|
# CreateToDo('ToDo', 'test1', '3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')
|