79 lines
2.4 KiB
Plaintext
79 lines
2.4 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os,re,json,time\n",
|
|
"\n",
|
|
"\"\"\"---设置原题目id与新题目id---\"\"\"\n",
|
|
"old_id = \"3648\"\n",
|
|
"new_id = \"31221\"\n",
|
|
"\"\"\"---设置完毕---\"\"\"\n",
|
|
"\n",
|
|
"old_id = old_id.zfill(6)\n",
|
|
"new_id = new_id.zfill(6)\n",
|
|
"\n",
|
|
"with open(r\"../题库0.3/Problems.json\",\"r\",encoding = \"utf8\") as f:\n",
|
|
" database = f.read()\n",
|
|
"\n",
|
|
"pro_dict = json.loads(database)\n",
|
|
"if new_id in pro_dict:\n",
|
|
" print(\"该ID已被使用.\")\n",
|
|
"else:\n",
|
|
" pro_dict[new_id] = {}\n",
|
|
" for field in pro_dict[old_id]:\n",
|
|
" if not field == \"id\":\n",
|
|
" pro_dict[new_id][field] = pro_dict[old_id][field] if not type(pro_dict[old_id][field]) == list else pro_dict[old_id][field].copy()\n",
|
|
" else:\n",
|
|
" pro_dict[new_id][field] = new_id\n",
|
|
" pro_dict[new_id][\"related\"].append(old_id)\n",
|
|
" pro_dict[new_id][\"same\"] = []\n",
|
|
" pro_dict[new_id][\"objs\"] = pro_dict[old_id][\"objs\"].copy()\n",
|
|
" pro_dict[new_id][\"usages\"] = []\n",
|
|
" pro_dict[new_id][\"edit\"].append(str(time.localtime().tm_year)+str(time.localtime().tm_mon).zfill(2)+str(time.localtime().tm_mday).zfill(2) + \"\\t\")\n",
|
|
" pro_dict[old_id][\"related\"].append(new_id)\n",
|
|
" pro_dict[new_id][\"origin\"] += \"-\" + str(time.localtime().tm_year)+str(time.localtime().tm_mon).zfill(2)+str(time.localtime().tm_mday).zfill(2) + \"修改\"\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))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "mathdept",
|
|
"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.9.15"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "ff3c292c316ba85de6f1ad75f19c731e79d694e741b6f515ec18f14996fe48dc"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|