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-20 22:48:23 +08:00
|
|
|
|
"""
|
|
|
|
|
: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-25 22:32:44 +08:00
|
|
|
|
print('<CreateToDo>' + uid)
|
2022-04-20 22:48:23 +08:00
|
|
|
|
if item_type == 'ToDoList':
|
|
|
|
|
try:
|
|
|
|
|
"""
|
|
|
|
|
createdAt : 创建时间
|
|
|
|
|
dueTo : 完成时间
|
|
|
|
|
itemType : 类型
|
|
|
|
|
notes : 笔记
|
|
|
|
|
title : 标题
|
|
|
|
|
updatedAt : 最后一次更新时间
|
|
|
|
|
"""
|
|
|
|
|
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-25 22:32:44 +08:00
|
|
|
|
"icon": '星宿',
|
2022-04-20 22:48:23 +08:00
|
|
|
|
"updatedAt": default_time
|
|
|
|
|
}
|
|
|
|
|
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)
|
2022-05-03 17:08:19 +08:00
|
|
|
|
return [name, uid, default_time, '星宿']
|
2022-04-20 22:48:23 +08:00
|
|
|
|
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
|
|
|
|
|
except IOError as e:
|
|
|
|
|
print(e)
|
|
|
|
|
return False
|
2022-04-17 22:36:19 +08:00
|
|
|
|
|
2022-04-25 22:32:44 +08:00
|
|
|
|
|
|
|
|
|
def create_myday_important(item_type, name):
|
|
|
|
|
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('<create_myday_important>' + uid)
|
|
|
|
|
out_config = {
|
|
|
|
|
"createdAt": default_time,
|
|
|
|
|
"done": False,
|
|
|
|
|
"dueTo": '',
|
|
|
|
|
"itemType": item_type,
|
|
|
|
|
"notes": "",
|
|
|
|
|
"isMyDay": False,
|
|
|
|
|
"isImportant": False,
|
|
|
|
|
"title": name,
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"updatedAt": default_time
|
|
|
|
|
}
|
|
|
|
|
try:
|
|
|
|
|
if item_type == 'MyDay':
|
|
|
|
|
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
|
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
#
|
|
|
|
|
# CreateToDo('ToDo', 'test1', '3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')
|