From 3c4d563f09c80316f0171b516a4909fcaf132671 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Thu, 1 Feb 2024 13:42:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=B2=E4=B9=89=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E7=BC=96=E5=8F=B7=E5=BD=95=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 17 ++++++++- 工具v2/讲义结构编号录入.py | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 工具v2/讲义结构编号录入.py diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 9fa59252..85c1e82d 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -146,7 +146,22 @@ def generate_number_set(string,*thedict): #根据可能含有":"和","的题号 numbers_list = [id for id in numbers_list if id in thedict[0]] return numbers_list #返回字典中存在的六位题号列表 else: - return "输入参数有误" + return "输入参数有误" + +def generate_id_set(string,*thedict): #除了生成题号列表外, 还能根据首字母生成基础知识编号列表或课时目标列表 + if re.findall(r"[BXK]",string) == []: + if thedict == (): + return generate_number_set(string) + else: + return generate_number_set(string,thedict) + else: + if string[0] == "B": + string = re.sub("B","",string) + return ["B"+i[-5:] for i in generate_number_set(string)] + elif string[0] == "K": + suffix = string.strip()[-1] + string = re.sub("[KBX]","",string) + return ["K"+i.zfill(7)+suffix for i in generate_number_set(string)] def generate_exp(id_list): #根据题号列表生成字符串式的含":"和","的题号字符串, 例如["000001","000002","000003","000005"]生成"000001:000003,000005", 若列表为空则生成"无有效题号" if not len(id_list) == 0: diff --git a/工具v2/讲义结构编号录入.py b/工具v2/讲义结构编号录入.py new file mode 100644 index 00000000..f1ec7ba7 --- /dev/null +++ b/工具v2/讲义结构编号录入.py @@ -0,0 +1,78 @@ +prefix = "Z202601" #第一个字母是分类的代号, 1-4为数字是届别, 5-6位数字一般是学期序号(01-06), 特殊情况酌情分类, 假期作业归属于前一个学期 + + +from database_tools import * + +jsonfile = f"../备课组/{prefix[3:5]}届/校本材料.json" +notes_dict = load_dict(jsonfile) + +# print(len(notes_dict)) +if not prefix[0] in notes_dict["structures"]: + AddNew = input("此类型不在列表中, 新增(A)/退出(Q):") + if AddNew[0].upper() == "A": + descr = input("类型描述:") + cn = input("编号是否连续(T/F):") + if cn[0].upper() == "T": + cn = True + else: + cn = False + partscount = int(input("分为多少个部分:")) + new_struct_dict = { + "description": descr, + "consecutivenumbering": cn, + "structure": {} + } + for i in range(partscount): + partid = input(f"第 {i+1} 部分的代号:") + partname = input(f"部分 {partid} 的名称:") + spaceflag = input(f"部分 {partid}: {partname} 中是否要在题目后留空格(T/F):") + if spaceflag[0].upper() == "T": + spaceflag = True + else: + spaceflag = False + new_struct_dict["structure"][partid] = { + "name": partname, + "spaceflag": spaceflag + } + notes_dict["structures"][prefix[0]] = new_struct_dict.copy() + save_dict(notes_dict,jsonfile) + else: + pass +else: + numberlist = [] + for id in notes_dict["notes"]: + if prefix in id: + numberlist.append(id[-2:]) + print("该分类下已有材料编号: "+generate_exp(numberlist)) + pid = prefix + input("请输入新材料编号(两位数):") + while pid in notes_dict["notes"]: + print("编号重复, 请重新输入.") + pid = prefix + input("请输入新材料编号(两位数):") + name = input("请输入材料名称:") + filenameraw = input("生成的文件名和材料名称是否一致?([Y]/如果不一致请输入文件名):") + if filenameraw.upper() == "Y": + filename = name + else: + filename = filenameraw + new_note_dict = { + "id": pid, + "name": name, + "filename": filename + } + structure = notes_dict['structures'][prefix[0]]['structure'] + print(f"此类材料共有 {len(structure)} 个部分, 分别是:") + for p in structure: + print(f"{p}: {structure[p]['name']}") + new_note_dict[p] = [] + for p in structure: + rawdata = input(f"现在输入 {p}: {structure[p]['name']} 部分的内容编号:") + rawdata = re.sub(r"[^BXK\d:,]","",rawdata) + if re.findall(r"\d",rawdata) == []: + new_note_dict[p] = [] + else: + new_note_dict[p] = generate_id_set(rawdata) + print(f"{p}: {new_note_dict[p]}") + notes_dict["notes"][pid] = new_note_dict.copy() + notes_dict["notes"] = SortDict(notes_dict["notes"]) + save_dict(notes_dict,jsonfile) +