修改 findxiaobenIDs 以适配讲义在mariadb上的情形
This commit is contained in:
parent
3a452a32b1
commit
22554f8eb2
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Reference in New Issue