From edc485d161f4d7108d31c9e42c99cec52fb579eb Mon Sep 17 00:00:00 2001 From: Wang Weiye Date: Mon, 5 Dec 2022 19:42:39 +0800 Subject: [PATCH] 20221205 afternoon --- 工具/修改题目数据库.ipynb | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/工具/修改题目数据库.ipynb b/工具/修改题目数据库.ipynb index ffc5c511..a1440e5c 100644 --- a/工具/修改题目数据库.ipynb +++ b/工具/修改题目数据库.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -11,7 +11,7 @@ "0" ] }, - "execution_count": 1, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -19,15 +19,30 @@ "source": [ "import os,re,json\n", "# 这里修改题目id, 可以不满6位\n", - "id = 5900\n", + "id = 1\n", "\n", "index = str(id).zfill(6)\n", "with open(r\"../题库0.3/Problems.json\",\"r\",encoding = \"utf8\") as f:\n", " database = f.read()\n", - "line = '\"id\": \"'+index+'\",'\n", - "before = database[:database.index(line)]\n", - "position = len(re.findall(r\"\\n\",before))\n", - "os.system(r\"code -g ../题库0.3/Problems.json:\" +str(position))" + "pro_dict = json.loads(database)\n", + "problem = pro_dict[index]\n", + "with open(r\"临时文件/problem_edit.json\",\"w\",encoding=\"u8\") as f:\n", + " f.write(json.dumps(problem,indent = 4,ensure_ascii=False))\n", + "os.system(r\"code -g 临时文件/problem_edit.json\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "with open(r\"临时文件/problem_edit.json\",\"r\",encoding=\"u8\") as f:\n", + " datanew = f.read()\n", + "new_pro = json.loads(datanew)\n", + "pro_dict[index] = new_pro.copy()\n", + "with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n", + " f.write(json.dumps(pro_dict,indent = 4,ensure_ascii=False))" ] }, { @@ -40,7 +55,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.8.8 ('base')", + "display_name": "Python 3.9.7 ('base')", "language": "python", "name": "python3" }, @@ -54,12 +69,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.9.7" }, "orig_nbformat": 4, "vscode": { "interpreter": { - "hash": "d311ffef239beb3b8f3764271728f3972d7b090c974f8e972fcdeedf230299ac" + "hash": "e4cce46d6be9934fbd27f9ca0432556941ea5bdf741d4f4d64c6cd7f8dfa8fba" } } },