pyqt-todolist/test/TestGetToDoList.py

57 lines
1.8 KiB
Python

import os
import json
import configparser
from utils import BasicUtils
def get_todo_list():
config_path = BasicUtils.return_work_dir()
todo_path = config_path + 'ToDoList/'
# print(todo_path)
# config = configparser.ConfigParser()
return_todo_list = []
for root, dirs, files in os.walk(todo_path, topdown=False):
for name in files:
# print(os.path.join(root, name))
with open(os.path.join(root, name), 'r') as f:
# print(f.read())
json_file = json.load(f)
# try:
if json_file['itemType'] == 'ToDoList':
# print(json_file['title'], json_file['uid'], '列表')
return_todo_list.append([json_file['title'], json_file['uid']])
# print(return_todo_list)
return return_todo_list
def get_to_do(todoListUid):
config_path = BasicUtils.return_work_dir()
todo_path = config_path + 'ToDoList/'
# print(todo_path)
# config = configparser.ConfigParser()
return_todo = []
for root, dirs, files in os.walk(todo_path, topdown=False):
for name in files:
# print(os.path.join(root, name))
with open(os.path.join(root, name), 'r') as f:
# print(f.read())
json_file = json.load(f)
# print(json_file['itemType'])
if json_file['itemType'] == 'Todo' and json_file['todoListUid'] == todoListUid:
# print(json_file['title'], json_file['uid'], '待办事项')
return_todo.append([json_file['title'], json_file['uid']])
return return_todo
# load_list = get_todo_list()
# print(load_list)
# if load_list:
# for load in load_list:
# print(load[0], load[1])
print(get_to_do('3f1e033f-2051-4c04-b7f6-afd2eb1f54f4'))