91 lines
2.9 KiB
Python
91 lines
2.9 KiB
Python
import os
|
||
import uuid
|
||
import json
|
||
from datetime import datetime
|
||
|
||
from utils import BasicUtils
|
||
|
||
"""
|
||
todo : 暂时创建单个文件存储该列表下所有待办事项,文件命名为 {uuid}.otl
|
||
同级还有 library.json 存储该列表信息
|
||
上一级创建一个配置文件,里边保存“我的一天”、“重要” 的 列表uuid/待办事项uuid
|
||
始终还是要读取文件,选择尽量少的读取和写入
|
||
(可以尝试在待办事项添加 isMyDay属性和isImportant属性)
|
||
"""
|
||
|
||
# class CreateToDo:
|
||
"""
|
||
:param item_type: 创建的类型,为ToDo和ToDoList
|
||
:param name: 要创建的ToDoList名字
|
||
:param todo_list_uid : 待办事项列表的uid,可选
|
||
"""
|
||
|
||
|
||
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
|
||
|
||
except IOError as e:
|
||
print(e)
|
||
return False
|
||
|
||
#
|
||
# CreateToDo('ToDo', 'test1', '3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')
|