2022-04-28 17:07:42 +08:00
|
|
|
import base64
|
2022-04-20 22:48:23 +08:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import platform
|
2022-04-21 22:42:43 +08:00
|
|
|
from datetime import datetime
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
def return_work_dir():
|
|
|
|
if platform.system() == 'Linux':
|
|
|
|
work_path = os.path.expandvars('$HOME') + '/.config/'
|
|
|
|
if not os.path.exists(work_path):
|
|
|
|
os.mkdir(work_path)
|
|
|
|
return os.path.expandvars('$HOME') + '/.config/PyQtToDoList/'
|
2022-04-28 17:07:42 +08:00
|
|
|
elif platform.system() == 'Windows':
|
|
|
|
work_path = os.getcwd() + '/../config/PyQtToDoList/'
|
|
|
|
if not os.path.exists(work_path):
|
|
|
|
os.mkdir(work_path)
|
|
|
|
return work_path
|
|
|
|
|
|
|
|
|
|
|
|
def return_config_dir():
|
|
|
|
if platform.system() == 'Linux':
|
|
|
|
work_path = os.path.expandvars('$HOME') + '/.config/'
|
|
|
|
if not os.path.exists(work_path):
|
|
|
|
os.mkdir(work_path)
|
|
|
|
return os.path.expandvars('$HOME') + '/.config/'
|
2022-04-20 22:48:23 +08:00
|
|
|
elif platform.system() == 'Windows':
|
2022-04-27 22:26:59 +08:00
|
|
|
work_path = os.getcwd() + '/../config/'
|
2022-04-20 22:48:23 +08:00
|
|
|
if not os.path.exists(work_path):
|
|
|
|
os.mkdir(work_path)
|
|
|
|
return work_path
|
|
|
|
|
|
|
|
|
|
|
|
import configparser
|
|
|
|
|
|
|
|
|
|
|
|
def read_init_file():
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
try:
|
|
|
|
config.read(return_work_dir() + 'PyQtToDoList.ini')
|
|
|
|
account = config['Account']
|
2022-04-28 17:07:42 +08:00
|
|
|
password = str(base64.b64decode(account['webdav_password']), 'utf-8')
|
2022-04-20 22:48:23 +08:00
|
|
|
if account:
|
2022-04-28 17:07:42 +08:00
|
|
|
return [account['webdav_hostname'], account['webdav_login'], password, account['type']]
|
2022-04-20 22:48:23 +08:00
|
|
|
except KeyError as e:
|
|
|
|
return False
|
2022-04-28 17:07:42 +08:00
|
|
|
except UnicodeError as e:
|
|
|
|
return False
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
|
|
|
2022-04-24 22:29:42 +08:00
|
|
|
def change_myday_important_conf(change_type, key, value):
|
|
|
|
value = str(value)
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config_path = return_work_dir()
|
|
|
|
todo_file = config_path + 'PyQtToDoList.conf'
|
|
|
|
if not os.path.exists(todo_file):
|
|
|
|
# print(True)
|
|
|
|
myday = {"Theme": "0"}
|
|
|
|
important = {"Theme": "0"}
|
|
|
|
config['MyDay'] = myday
|
|
|
|
config['Important'] = important
|
|
|
|
with open(todo_file, 'w') as f:
|
|
|
|
config.write(f)
|
|
|
|
|
|
|
|
config.read(todo_file)
|
|
|
|
config[change_type][key] = value
|
|
|
|
with open(todo_file, 'w') as f:
|
|
|
|
config.write(f)
|
|
|
|
|
|
|
|
|
|
|
|
def get_myday_important_conf(get_type, key):
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config_path = return_work_dir()
|
2022-04-27 21:39:09 +08:00
|
|
|
try:
|
|
|
|
todo_file = config_path + 'PyQtToDoList.conf'
|
|
|
|
config.read(todo_file)
|
|
|
|
return config[get_type][key]
|
|
|
|
except KeyError as e:
|
|
|
|
print('File Not Found!')
|
|
|
|
return False
|
2022-04-24 22:29:42 +08:00
|
|
|
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
def get_todo_list():
|
|
|
|
config_path = return_work_dir()
|
|
|
|
todo_path = config_path + 'ToDoList/'
|
|
|
|
# print(todo_path)
|
|
|
|
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'], '列表')
|
2022-04-25 22:32:44 +08:00
|
|
|
return_todo_list.append(
|
|
|
|
[json_file['title'], json_file['uid'], json_file['updatedAt'], json_file['icon']])
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
|
|
# print(return_todo_list)
|
2022-04-23 17:36:22 +08:00
|
|
|
return_todo_list.sort(key=get_third)
|
2022-04-20 22:48:23 +08:00
|
|
|
return return_todo_list
|
|
|
|
|
|
|
|
|
|
|
|
def get_todo(todoListUid):
|
|
|
|
config_path = 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'])
|
2022-04-21 22:42:43 +08:00
|
|
|
if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file[
|
|
|
|
'todoListUid'] == todoListUid:
|
2022-04-20 22:48:23 +08:00
|
|
|
# print(json_file['title'], json_file['uid'], '待办事项')
|
2022-04-23 17:36:22 +08:00
|
|
|
return_todo.append([json_file['title'], json_file['uid'], json_file['updatedAt']])
|
|
|
|
return_todo.sort(key=get_third)
|
2022-04-21 22:42:43 +08:00
|
|
|
return return_todo
|
2022-04-20 22:48:23 +08:00
|
|
|
|
2022-04-21 22:42:43 +08:00
|
|
|
# load_list = get_todo_list()
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
def load_myday_important(item_type):
|
|
|
|
config_path = 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 item_type == 'MyDay':
|
2022-04-21 22:42:43 +08:00
|
|
|
if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isMyDay']:
|
2022-04-20 22:48:23 +08:00
|
|
|
# print(json_file['title'], json_file['uid'], '待办事项')
|
2022-04-23 17:36:22 +08:00
|
|
|
return_todo.append([json_file['title'], json_file['uid'], json_file['updatedAt']])
|
2022-04-22 22:09:38 +08:00
|
|
|
# return return_todo
|
2022-04-20 22:48:23 +08:00
|
|
|
elif item_type == 'Important':
|
2022-04-21 22:42:43 +08:00
|
|
|
if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isImportant']:
|
2022-04-20 22:48:23 +08:00
|
|
|
# print(json_file['title'], json_file['uid'], '待办事项')
|
2022-04-23 17:36:22 +08:00
|
|
|
return_todo.append([json_file['title'], json_file['uid'], json_file['updatedAt']])
|
2022-04-22 22:09:38 +08:00
|
|
|
# print(return_todo)
|
2022-04-23 17:36:22 +08:00
|
|
|
return_todo.sort(key=get_third)
|
2022-04-21 22:42:43 +08:00
|
|
|
return return_todo
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
|
|
|
2022-04-23 17:36:22 +08:00
|
|
|
def get_third(elem):
|
|
|
|
return elem[2]
|
|
|
|
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
# 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等
|
|
|
|
def change_value(uid, key, value):
|
|
|
|
config_path = return_work_dir()
|
|
|
|
todo_path = config_path + 'ToDoList/'
|
|
|
|
|
|
|
|
json_file = {}
|
2022-04-21 22:42:43 +08:00
|
|
|
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
|
|
with open(todo_path + '{' + uid + '}.otl', 'r') as f:
|
|
|
|
# print(f.read())
|
|
|
|
json_file = json.load(f)
|
2022-04-22 22:09:38 +08:00
|
|
|
# print('<BasicUtils>'+json_file)
|
2022-04-20 22:48:23 +08:00
|
|
|
json_file[key] = value
|
2022-04-21 22:42:43 +08:00
|
|
|
json_file['updatedAt'] = current_time
|
2022-04-20 22:48:23 +08:00
|
|
|
# print(json_file[key])
|
|
|
|
with open(todo_path + '{' + uid + '}.otl', 'w') as f:
|
|
|
|
json.dump(json_file, f, indent=4, ensure_ascii=False)
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
|
|
|
def load_value(uid, key):
|
|
|
|
config_path = return_work_dir()
|
|
|
|
todo_path = config_path + 'ToDoList/'
|
|
|
|
|
|
|
|
with open(todo_path + '{' + uid + '}.otl', 'r') as f:
|
|
|
|
# print(f.read())
|
|
|
|
json_file = json.load(f)
|
|
|
|
# print('<BasicUtils>'+json_file)
|
|
|
|
return json_file[key]
|
|
|
|
|
|
|
|
|
|
|
|
def remove_todo_list(uid):
|
|
|
|
config_path = return_work_dir()
|
|
|
|
todo_path = config_path + 'ToDoList/'
|
|
|
|
os.remove(todo_path + '{' + uid + '}.otl')
|
2022-04-24 22:29:42 +08:00
|
|
|
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'] == uid:
|
|
|
|
# print(os.path.join(root, name))
|
|
|
|
os.remove(os.path.join(root, name))
|
|
|
|
|
2022-04-26 17:07:00 +08:00
|
|
|
|
|
|
|
def read_ini(section, key):
|
|
|
|
config_path = return_work_dir()
|
|
|
|
try:
|
|
|
|
ini_path = config_path + 'PyQtToDoList.ini'
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(ini_path)
|
|
|
|
return config[section][key]
|
|
|
|
except Exception as e:
|
|
|
|
print('<BasicUtils>', e)
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def set_exit_status(status):
|
|
|
|
config_path = return_work_dir()
|
|
|
|
try:
|
|
|
|
ini_path = config_path + 'PyQtToDoList.ini'
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(ini_path)
|
|
|
|
config['System']['exitstatus'] = status
|
|
|
|
# print(config['S'])
|
|
|
|
with open(ini_path, 'w') as f:
|
|
|
|
config.write(f)
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
|
|
print('<BasicUtils>', e)
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2022-04-27 21:39:09 +08:00
|
|
|
# 判断是否登录
|
|
|
|
def check_login_status():
|
|
|
|
try:
|
|
|
|
# work_dir = return_work_dir()
|
|
|
|
init_file_list = read_init_file()
|
|
|
|
print(init_file_list)
|
|
|
|
if init_file_list and 'None' not in init_file_list:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
#
|
|
|
|
# for i in init_file_list:
|
|
|
|
# if i == 'None':
|
|
|
|
# return False
|
|
|
|
# else:
|
|
|
|
# return True
|
|
|
|
except TypeError as e:
|
|
|
|
return False
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
# print(read_init_file())
|
|
|
|
# webdav_hostname = read_init_file()
|
|
|
|
# print(webdav_hostname[2])
|
2022-04-21 22:42:43 +08:00
|
|
|
# change_value('4f52f02b-4450-405a-9fd1-2005a03006e0', 'isMyDay', False)
|
|
|
|
# print(get_todo('3f1e033f-2051-4c04-b7f6-afd2eb1f54f4'))
|
|
|
|
# print(load_myday_important('Important'))
|
2022-04-24 22:29:42 +08:00
|
|
|
# change_myday_important_conf('Important', 'theme', 2)
|
2022-04-25 22:32:44 +08:00
|
|
|
# print(get_myday_important_conf('Important','Theme'))
|
2022-04-26 17:07:00 +08:00
|
|
|
# print(read_ini('System', 'exitstatus'))
|
|
|
|
# print(set_exit_status('Min'))
|
2022-04-27 21:39:09 +08:00
|
|
|
# print(check_login_status())
|