{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os,re,json\n",
    "\n",
    "#范围定义在使用前需要替换\n",
    "\"\"\"使用前替换范围定义\"\"\"\n",
    "obj_range = \"K0227001X:K0240999X\"\n",
    "\"\"\"范围定义到此结束\"\"\"\n",
    "\n",
    "\n",
    "# 检查某一字符串是否在由,:的表达式给出的范围内\n",
    "def within_range(string,list):\n",
    "    flag = False\n",
    "    for item in list:\n",
    "        if string == item.strip():\n",
    "            flag = True\n",
    "            break\n",
    "        elif \":\" in item:\n",
    "            start, end = item.split(\":\")\n",
    "            if start <= string <= end:\n",
    "                flag = True\n",
    "                break\n",
    "    return flag\n",
    "\n",
    "# 读取课时目标数据库\n",
    "with open(r\"../题库0.3/LessonObj.json\",\"r\",encoding = \"utf8\") as f:\n",
    "    database = f.read()\n",
    "obj_dict = json.loads(database)\n",
    "\n",
    "# 根据范围生成若干用于检查的闭区间范围\n",
    "obj_range_list = obj_range.split(\",\")\n",
    "output_string = \"\"\n",
    "\n",
    "# 逐一选择目标, 并整合成表格的内容部分\n",
    "for obj_id in obj_dict:\n",
    "    if within_range(obj_id,obj_range_list):\n",
    "        output_string += obj_id + \" & \" + obj_dict[obj_id][\"content\"] + \" & \" + r\"\\\\ \\hline\" + \"\\n\"\n",
    "\n",
    "#输出到临时文件夹\n",
    "with open(r\"临时文件/课时目标提取结果.tex\",\"w\",encoding = \"utf8\") as f:\n",
    "    f.write(output_string)"
   ]
  },
  {
   "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
}
