From 14b7c03a7ca5e0b8d61f1ac3c90ce22b75626e41 Mon Sep 17 00:00:00 2001 From: liyp Date: Sun, 17 Apr 2022 22:36:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=87=86=E5=A4=87=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BF=9D=E5=AD=98=E5=92=8C=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/TimeTest.py | 5 +++ utils/CreateConfigure.py | 3 ++ utils/CreateToDo.py | 86 +++++++++++++++++++++++++++++++++++++++ utils/CreateToDoConfig.py | 37 +++++++++++++++++ utils/CreateToDoList.py | 5 --- utils/LoginAction.py | 42 +++++++++++++++++++ utils/NextCloud.py | 15 ------- 7 files changed, 173 insertions(+), 20 deletions(-) create mode 100644 utils/CreateConfigure.py create mode 100644 utils/CreateToDoConfig.py delete mode 100644 utils/CreateToDoList.py create mode 100644 utils/LoginAction.py delete mode 100644 utils/NextCloud.py diff --git a/test/TimeTest.py b/test/TimeTest.py index ebd5687..f4e96f5 100644 --- a/test/TimeTest.py +++ b/test/TimeTest.py @@ -5,4 +5,9 @@ weekday = ["星期一", "星期二", "星期三", "星期四", "星期五", "星 weekday_index = datetime.datetime.now().weekday() month = datetime.datetime.now().month day = datetime.datetime.now().day +print(datetime.datetime.now()) print(str(month) + '月' + str(day) + '日,' + weekday[weekday_index]) +time1 = '2022-04-17 20:39:10.242742' +time2 = datetime.datetime.now().strptime('2022-04-17 20:39:10', '%Y-%m-%d %H:%M:%S') +print(time2, type(time2)) +print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) diff --git a/utils/CreateConfigure.py b/utils/CreateConfigure.py new file mode 100644 index 0000000..c3bbfb1 --- /dev/null +++ b/utils/CreateConfigure.py @@ -0,0 +1,3 @@ + + +# todo : 用来创建软件的配置信息 \ No newline at end of file diff --git a/utils/CreateToDo.py b/utils/CreateToDo.py index e69de29..0fb17a2 100644 --- a/utils/CreateToDo.py +++ b/utils/CreateToDo.py @@ -0,0 +1,86 @@ +import os +import platform +import uuid +import json +from datetime import datetime + +""" + 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 = self.get_config_path() + todo_list_path = config_path + '/{' + uid + '}' + default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + 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' diff --git a/utils/CreateToDoConfig.py b/utils/CreateToDoConfig.py new file mode 100644 index 0000000..cca4728 --- /dev/null +++ b/utils/CreateToDoConfig.py @@ -0,0 +1,37 @@ +import os +import platform +import uuid +import json + + +class CreateConfig: + """ + :param title: 配置文件的 + """ + + def __init__(self, title): + uid = str(uuid.uuid4()) + config_path = self.get_config_path() + todo_list_path = config_path + '/{' + uid + '}' + try: + os.mkdir(todo_list_path) + library = { + "title": title, + "uid": uuid + } + with open(todo_list_path + '/library.json', 'w') as f: + f.write(json.dumps(library)) + except IOError as e: + print(e) + pass + + 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' diff --git a/utils/CreateToDoList.py b/utils/CreateToDoList.py deleted file mode 100644 index 347890b..0000000 --- a/utils/CreateToDoList.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - -print(os.environ['HOME']) -print(os.path.expandvars('~')) -print(os.path.expandvars('$HOME')) diff --git a/utils/LoginAction.py b/utils/LoginAction.py new file mode 100644 index 0000000..b68ebd8 --- /dev/null +++ b/utils/LoginAction.py @@ -0,0 +1,42 @@ +from webdav3.client import Client + + +class LoginAction: + """ + :param login_type : 登录方式 有 NextCloud、JianGuoYun、WebDav + :param webdav_login : 登录用户名 + :param webdav_password : 登录密码 + :param webdav_hostname : 服务地址 + """ + + def __init__(self, login_type, webdav_login, webdav_password, webdav_hostname=None): + options = {} + if login_type == 'NextCloud': + webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] == '/' else webdav_hostname + options = { + 'webdav_hostname': webdav_hostname + "remote.php/dav/files/admin/", + 'webdav_login': webdav_login, + 'webdav_password': webdav_password + } + elif login_type == 'JianGuoYun': + options = { + 'webdav_hostname': "https://dav.jianguoyun.com/dav/", + 'webdav_login': webdav_login, + 'webdav_password': webdav_password + } + elif login_type == 'WebDav': + webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] == '/' else webdav_hostname + options = { + 'webdav_hostname': webdav_hostname, + 'webdav_login': webdav_login, + 'webdav_password': webdav_password + } + + client = Client(options) + # client.execute_request('list') + list1 = client.list('/') + print(list1) + exist = client.check('OpenTodoList') + print(exist) + if not exist: + client.mkdir('OpenTodoList') diff --git a/utils/NextCloud.py b/utils/NextCloud.py deleted file mode 100644 index 629124c..0000000 --- a/utils/NextCloud.py +++ /dev/null @@ -1,15 +0,0 @@ -from webdav3.client import Client - -import configparser - -options = { - 'webdav_hostname': "https://cloud.liyp.cc/remote.php/dav/files/admin/", - 'webdav_login': "admin", - 'webdav_password': "" -} -client = Client(options) -# client.execute_request('list') -list1 = client.list('/') -print(list1) -exist = client.check('OpenTodoList') -print(exist)