From 22554f8eb27aadcd94b03aa3c0e832e34cbb64ad Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Sun, 16 Jun 2024 16:37:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20findxiaobenIDs=20=E4=BB=A5?= =?UTF-8?q?=E9=80=82=E9=85=8D=E8=AE=B2=E4=B9=89=E5=9C=A8mariadb=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index c26193af..75c00d32 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -3285,19 +3285,21 @@ def isIDpart(alist): #判断一个list是不是题号列表 return True -def findxiaobenIDs(jsonpath,grade = ""): #根据jsonpath中的校本材料获取grade做过的题目, grade为空则获取所有目录中的题目 - jsonlists = [] +def findxiaobenIDs(cursor,grade = ""): #根据jsonpath中的校本材料获取grade做过的题目, grade为空则获取所有目录中的题目 + sql = 'SELECT nid,structure FROM notes WHERE NOT obsolete;' + cursor.execute(sql) + ret = cursor.fetchall() + grade = grade.strip() + if len(grade) == 2: + grade = "20"+grade jsonIDs = [] - for loc,dirs,files in os.walk(jsonpath): - if "校本材料.json" in files: - jsonlists.append(os.path.join(loc,"校本材料.json")) - for jsonfile in jsonlists: - jsondict = load_dict(jsonfile)["notes"] - for pid in jsondict: - if pid[1:5] == grade or grade == "": - for part in jsondict[pid]: - if type(jsondict[pid][part]) == list and isIDpart(jsondict[pid][part]): - jsonIDs += jsondict[pid][part].copy() + for nid,structure in ret: + if grade == "" or nid[1:5] == grade: + structure = json.loads(structure) + for key in structure: + for id in structure[key]: + if len(id) == 6: + jsonIDs.append(id) return jsonIDs