106 lines
3.3 KiB
Python
106 lines
3.3 KiB
Python
import os
|
||
import uuid
|
||
import json
|
||
from datetime import datetime
|
||
|
||
from utils import BasicUtils
|
||
|
||
"""
|
||
: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':
|
||
try:
|
||
"""
|
||
createdAt : 创建时间
|
||
dueTo : 完成时间
|
||
itemType : 类型
|
||
notes : 笔记
|
||
title : 标题
|
||
updatedAt : 最后一次更新时间
|
||
"""
|
||
out_config = {
|
||
"createdAt": default_time,
|
||
"dueTo": '',
|
||
"itemType": item_type,
|
||
"notes": "",
|
||
"title": name,
|
||
"uid": uid,
|
||
"Theme": '0',
|
||
"icon": '星宿',
|
||
"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)
|
||
return [name, uid, default_time, '星宿']
|
||
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
|
||
|
||
|
||
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
|
||
|
||
#
|
||
# CreateToDo('ToDo', 'test1', '3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')
|