From ca58acf66b48bccad2e0e8d0ebb21e4f5c8396c9 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Mon, 15 Apr 2024 06:48:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=B3=E8=81=94=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=20=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v3/database_tools_2.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/工具v3/database_tools_2.py b/工具v3/database_tools_2.py index 823abfb3..90634ea0 100644 --- a/工具v3/database_tools_2.py +++ b/工具v3/database_tools_2.py @@ -400,7 +400,34 @@ def CreateNewProblem(id,content,origin,dict,editor): # 构建一道新题目的 return NewProblem # 返回一道新题目的字典, 已赋新的ID, 内容, 来源和编辑者 def AddRelatedProblemToDB(id,content,oid,editor): - pass + mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest") + mycursor = mydb.cursor() + id = str(id).zfill(6) + if "blank" in content: + genre = "填空题" + space = "" + elif "bracket" in content: + genre = "选择题" + space = "" + else: + genre = "解答题" + space = "4em" + origin_json = {"来源": "改编题目", "前序": str(oid).zfill(6)} + origin = json.dumps(origin_json,ensure_ascii=False) + sql = "INSERT INTO problems (ID,content,genre,origin,space) VALUE (%s,%s,%s,%s,%s);" + val = (id,content,genre,origin,space) + mycursor.execute(sql,val) + sql = "INSERT INTO edit_history (ID,date,editor) VALUE (%s,%s,%s);" + val = (id,GetDate(),editor.strip()) + mycursor.execute(sql,val) + sql = "INSERT INTO related (ID,RELATED_ID) VALUE (%s,%s);" + val = (id, oid) + if id > oid: + val = (oid, id) + mycursor.execute(sql,val) + mydb.commit() + mydb.close() + return id def AddProblemstoDict2024(startingid,raworigin,problems,editor,indexed): #将来自GenerateProblemListFromString的列表中的题目添加到thedict字典, 返回题号列表(包括用老题号替代的题目) mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest")