90 lines
3.2 KiB
Python
90 lines
3.2 KiB
Python
import os
|
||
import uuid
|
||
import json
|
||
from datetime import datetime
|
||
|
||
from utils import ReturnWorkDir
|
||
|
||
"""
|
||
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 __init__(self, item_type, name, todo_list_uid=None):
|
||
uid = str(uuid.uuid4())
|
||
config_path = ReturnWorkDir.return_work_dir()
|
||
todo_list_path = config_path + '{' + uid + '}'
|
||
# 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(default_time)
|
||
if item_type == 'ToDoList':
|
||
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,
|
||
"updatedAt": default_time
|
||
}
|
||
library = {
|
||
"title": name,
|
||
"uid": uid
|
||
}
|
||
with open(todo_list_path + '/library.json', 'w') as f:
|
||
f.write(json.dumps(library))
|
||
except IOError as e:
|
||
print(e)
|
||
elif item_type == 'ToDo':
|
||
try:
|
||
# done : 完成状态
|
||
# todoListUid : 父列表id
|
||
out_config = {
|
||
"createdAt": default_time,
|
||
"done": False,
|
||
"dueTo": '',
|
||
"itemType": "Todo",
|
||
"notes": "",
|
||
"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))
|
||
except IOError as e:
|
||
print(e)
|
||
|
||
# def get_config_path(self):
|
||
#
|
||
# # print(platform.system())
|
||
# if platform.system() == 'Linux':
|
||
# # print(os.environ['HOME'] + '/.config/PyQtToDoList')
|
||
# # print(os.path.expandvars('~'))
|
||
# # print(os.path.expandvars('$HOME') + '.config/PyQtToDoList')
|
||
# return os.path.expandvars('$HOME') + '/.config/PyQtToDoList'
|
||
# elif platform.system() == 'Windows':
|
||
# print(os.getcwd() + 'config')
|
||
# return os.getcwd() + 'config'
|