添加README
This commit is contained in:
@@ -28,7 +28,7 @@ class Course:
|
||||
def load_course_from_json(course_id, course_data_dir = None)-> Course:
|
||||
try:
|
||||
COURSE_DATA_DIR = course_data_dir if course_data_dir else LOCAL_COURSE_DATA_DIR
|
||||
with open(os.path.join(COURSE_DATA_DIR, f'{course_id}.json'), "r") as f:
|
||||
with open(os.path.join(COURSE_DATA_DIR, f'{course_id}.json'), "r", encoding='utf-8') as f:
|
||||
raw_json = f.read()
|
||||
user_data = json.loads(raw_json)
|
||||
return Course(**user_data)
|
||||
|
||||
@@ -4,7 +4,7 @@ import re
|
||||
class CourseList:
|
||||
def __init__(self, db_file='db/data/course/course_list.json'):
|
||||
self.db_file = db_file
|
||||
with open(self.db_file, 'r') as f:
|
||||
with open(self.db_file, 'r', encoding='utf-8') as f:
|
||||
self.db = json.load(f)
|
||||
|
||||
def add_course(self, course_id, course_name, course_create_date, course_update_data, course_img_path):
|
||||
@@ -17,7 +17,7 @@ class CourseList:
|
||||
self.db[course_id]['course_update_data'] = course_update_data
|
||||
self.db[course_id]['course_img_path'] = course_img_path
|
||||
|
||||
with open(self.db_file, 'w') as f:
|
||||
with open(self.db_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.db, f, indent=4)
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class CourseList:
|
||||
self.db[course_id]['course_update_data'] = course_update_data
|
||||
self.db[course_id]['course_img_path'] = course_img_path
|
||||
|
||||
with open(self.db_file, 'w') as f:
|
||||
with open(self.db_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.db, f, indent=4)
|
||||
|
||||
def delete_course(self, course_id):
|
||||
|
||||
@@ -71,13 +71,13 @@ class User:
|
||||
self.course_process_dict[course_id]['lesson_processs'].append(([], lesson['lesson_id']))
|
||||
|
||||
|
||||
with open(self.save_path, 'w') as f:
|
||||
with open(self.save_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.__json__(), f, indent=4)
|
||||
|
||||
def save_to_file(self):
|
||||
print(f"saved at {self.save_path}")
|
||||
self.get_course_progress()
|
||||
with open(self.save_path, 'w') as f:
|
||||
with open(self.save_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.__json__(), f, indent=4)
|
||||
|
||||
def __json__(self):
|
||||
@@ -106,14 +106,14 @@ class User:
|
||||
|
||||
def load_user_from_json(user_id, user_data_dir = None)-> User:
|
||||
USER_DATA_DIR = user_data_dir if user_data_dir else LOCAL_USER_DATA_DIR
|
||||
with open(os.path.join(USER_DATA_DIR, f'{user_id}.json'), "r") as f:
|
||||
with open(os.path.join(USER_DATA_DIR, f'{user_id}.json'), "r", encoding='utf-8') as f:
|
||||
raw_json = f.read()
|
||||
user_data = json.loads(raw_json)
|
||||
return User(save_path = os.path.join(USER_DATA_DIR, f'{user_id}.json'), **user_data)
|
||||
|
||||
def create_user_json(user_id, user_data_dir = None):
|
||||
USER_DATA_DIR = user_data_dir if user_data_dir else LOCAL_USER_DATA_DIR
|
||||
with open(os.path.join(USER_DATA_DIR, f'{user_id}.json'), "w") as f:
|
||||
with open(os.path.join(USER_DATA_DIR, f'{user_id}.json'), "w", encoding='utf-8') as f:
|
||||
f.write(json.dumps({
|
||||
'user_id': user_id,
|
||||
'select_course': [],
|
||||
|
||||
@@ -4,7 +4,7 @@ class UserList:
|
||||
def __init__(self, db_file='db/data/user/user_id_list.json'):
|
||||
"""初始化用户管理,自动打开并加载 JSON 数据文件。"""
|
||||
self.db_file = db_file
|
||||
with open(self.db_file, 'r') as f:
|
||||
with open(self.db_file, 'r', encoding='utf-8') as f:
|
||||
self.db = json.load(f)
|
||||
|
||||
def add_user(self, user_id, password):
|
||||
@@ -12,7 +12,7 @@ class UserList:
|
||||
# 检查是否已经有该用户
|
||||
if user_id not in self.db:
|
||||
self.db[user_id] = password
|
||||
with open(self.db_file, 'w') as f:
|
||||
with open(self.db_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.db, f, indent=4)
|
||||
else:
|
||||
print(f"User with ID {user_id} already exists.")
|
||||
@@ -32,7 +32,7 @@ class UserList:
|
||||
"""更新用户的密码"""
|
||||
assert self.db.get(user_id) is not None, f"User with ID {user_id} does not exist."
|
||||
self.db[user_id] = new_password
|
||||
with open(self.db_file, 'w') as f:
|
||||
with open(self.db_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.db, f, indent=4)
|
||||
|
||||
def delete_user(self, user_id):
|
||||
|
||||
Reference in New Issue
Block a user