{ "cells": [ { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "import os,re,json\n", "with open(r\"../题库0.3/problems.json\",\"r\",encoding = \"utf8\") as f:\n", " jsondata = f.read()\n", "pro_dict = json.loads(jsondata)\n", "id = input(\"输入题目id:\")\n", "id = id.zfill(6)\n", "content = pro_dict[id][\"content\"]\n", "\n", "with open(r\"模板文件/题目编辑.tex\",\"r\",encoding = \"utf8\") as f:\n", " template_data = f.read()\n", "\n", "output_data = template_data.replace(\"待替换\",content)\n", "with open(r\"临时文件/toedit.tex\",\"w\",encoding = \"utf8\") as f:\n", " f.write(output_data)\n", "\n", "os.system(\"code 临时文件/toedit.tex\")\n", "cont = input(\"继续请按回车\")\n", "with open(r\"临时文件/toedit.tex\",\"r\",encoding = \"utf8\") as f:\n", " edited_data = f.read()\n", "new_content = re.findall(r\"\\\\begin{document}([\\s\\S]*?)\\\\end{document}\",edited_data)[0].strip()\n", "pro_dict[id][\"content\"] = new_content\n", "\n", "jsondata_new=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(jsondata_new)\n" ] }, { "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 }