pyqt-todolist/utils/CreateToDo.py

92 lines
2.9 KiB
Python
Raw Normal View History

2022-04-17 22:36:19 +08:00
import os
import uuid
import json
from datetime import datetime
from utils import BasicUtils
2022-04-17 22:36:19 +08:00
"""
todo : 暂时创建单个文件存储该列表下所有待办事项,文件命名为 {uuid}.otl
同级还有 library.json 存储该列表信息
上一级创建一个配置文件里边保存我的一天重要 列表uuid/待办事项uuid
始终还是要读取文件选择尽量少的读取和写入
可以尝试在待办事项添加 isMyDay属性和isImportant属性
"""
# class CreateToDo:
"""
:param item_type: 创建的类型为ToDo和ToDoList
:param name: 要创建的ToDoList名字
:param todo_list_uid : 待办事项列表的uid,可选
"""
2022-04-17 22:36:19 +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')
print('<CreateToDo>'+uid)
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,
"Theme": '0',
"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
elif item_type == 'Todo':
try:
# done : 完成状态
# todoListUid 父列表id
out_config = {
"createdAt": default_time,
"done": False,
"dueTo": '',
"itemType": item_type,
"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
except IOError as e:
print(e)
return False
2022-04-17 22:36:19 +08:00
#
# CreateToDo('ToDo', 'test1', '3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')