{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "012287 填空题\n", "012288 填空题\n", "012289 填空题\n", "012290 填空题\n", "012291 填空题\n", "012292 填空题\n", "012293 填空题\n", "012294 填空题\n", "012295 填空题\n", "012296 填空题\n", "012297 填空题\n", "012298 填空题\n", "012299 选择题\n", "012300 选择题\n", "012301 选择题\n", "012302 选择题\n", "012303 解答题\n", "012304 解答题\n", "012305 解答题\n", "012306 解答题\n", "012307 解答题\n", "012308 填空题\n", "012309 填空题\n", "012310 填空题\n", "012311 填空题\n", "012312 填空题\n", "012313 填空题\n", "012314 填空题\n", "012315 填空题\n", "012316 填空题\n", "012317 填空题\n", "012318 填空题\n", "012319 填空题\n", "012320 选择题\n", "012321 选择题\n", "012322 选择题\n", "012323 选择题\n", "012324 解答题\n", "012325 解答题\n", "012326 解答题\n", "012327 解答题\n", "012328 解答题\n" ] } ], "source": [ "import os,re,json\n", "\n", "# 读取数据库并转成题目字典\n", "with open(r\"../题库0.3/Problems.json\",\"r\",encoding = \"utf8\") as f:\n", " database = f.read()\n", "pro_dict = json.loads(database)\n", "\n", "#根据特征字符识别题目类型\n", "for p in pro_dict:\n", " if pro_dict[p][\"genre\"] == \"\":\n", " if \"bracket\" in pro_dict[p][\"content\"]:\n", " pro_dict[p][\"genre\"] = \"选择题\"\n", " print(p,\"选择题\")\n", " elif \"blank\" in pro_dict[p][\"content\"]:\n", " pro_dict[p][\"genre\"] = \"填空题\"\n", " print(p,\"填空题\")\n", " else:\n", " pro_dict[p][\"genre\"] = \"解答题\"\n", " pro_dict[p][\"space\"] = \"12ex\"\n", " print(p,\"解答题\")\n", "\n", "#将修改结果写入json数据库\n", "database = json.dumps(pro_dict,indent = 4, ensure_ascii= False)\n", "with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n", " f.write(database)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.8 ('base')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d311ffef239beb3b8f3764271728f3972d7b090c974f8e972fcdeedf230299ac" } } }, "nbformat": 4, "nbformat_minor": 2 }