开始准备配置保存和同步

This commit is contained in:
liyp 2022-04-17 22:36:19 +08:00
parent 944b660d84
commit 14b7c03a7c
7 changed files with 173 additions and 20 deletions

View file

@ -5,4 +5,9 @@ weekday = ["星期一", "星期二", "星期三", "星期四", "星期五", "星
weekday_index = datetime.datetime.now().weekday() weekday_index = datetime.datetime.now().weekday()
month = datetime.datetime.now().month month = datetime.datetime.now().month
day = datetime.datetime.now().day day = datetime.datetime.now().day
print(datetime.datetime.now())
print(str(month) + '' + str(day) + '日,' + weekday[weekday_index]) 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'))

3
utils/CreateConfigure.py Normal file
View file

@ -0,0 +1,3 @@
# todo : 用来创建软件的配置信息

View file

@ -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'

37
utils/CreateToDoConfig.py Normal file
View file

@ -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'

View file

@ -1,5 +0,0 @@
import os
print(os.environ['HOME'])
print(os.path.expandvars('~'))
print(os.path.expandvars('$HOME'))

42
utils/LoginAction.py Normal file
View file

@ -0,0 +1,42 @@
from webdav3.client import Client
class LoginAction:
"""
:param login_type : 登录方式 NextCloudJianGuoYunWebDav
: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')

View file

@ -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)