{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os,re,json,time\n",
    "\n",
    "\"\"\"---设置原题目id与新题目id---\"\"\"\n",
    "old_id = \"4656\"\n",
    "new_id = \"30282\"\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": "Python 3.9.7 ('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.9.7"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "e4cce46d6be9934fbd27f9ca0432556941ea5bdf741d4f4d64c6cd7f8dfa8fba"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
