114 lines
3.2 KiB
Plaintext
114 lines
3.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"首行题目数量: 153\n",
|
|
"剩余题目数量: 148\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os,re\n",
|
|
"\n",
|
|
"\"\"\"---设置题号列表所在文件, 仅第一行有用---\"\"\"\n",
|
|
"id_list_file = \"文本文件/题号筛选.txt\"\n",
|
|
"\"\"\"---设置题号列表文件结束---\"\"\"\n",
|
|
"\n",
|
|
"\"\"\"---设置要排除的题号所在的绝对路径---\"\"\"\n",
|
|
"mainpath = r\"C:/Users/Weiye/Documents/wwy sync/23届/\"\n",
|
|
"\n",
|
|
"used_path_list = [\n",
|
|
"mainpath + \"第一轮复习讲义/\",\n",
|
|
"mainpath + \"上学期测验卷/\",\n",
|
|
"mainpath + \"上学期周末卷/\",\n",
|
|
"mainpath + \"赋能/\",\n",
|
|
"# mainpath + \"简单题/\",\n",
|
|
"]\n",
|
|
"\"\"\"---路径设置完毕---\"\"\"\n",
|
|
"\n",
|
|
"# 从字符串中获取题号列表\n",
|
|
"def extract_idlist(string):\n",
|
|
" idlist = re.findall(r\"\\(([\\d]{6})\\)\",string)\n",
|
|
" return idlist\n",
|
|
"\n",
|
|
"# 生成首行题号列表并输出数量\n",
|
|
"with open(id_list_file,\"r\",encoding = \"utf8\") as f:\n",
|
|
" data = f.read() + \"\\n\"\n",
|
|
"\n",
|
|
"id_list = re.findall(r\"^([^\\n]*)\\n\",data)[0].split(\",\")\n",
|
|
"print(\"首行题目数量: \",len(id_list))\n",
|
|
"\n",
|
|
"# 生成已使用题号列表\n",
|
|
"used_id_list = []\n",
|
|
"\n",
|
|
"for path in used_path_list:\n",
|
|
" filelist = [f for f in os.listdir(path) if \".tex\" in f]\n",
|
|
" for f in filelist:\n",
|
|
" with open(path+f,\"r\",encoding = \"utf8\") as texfile:\n",
|
|
" texdata = texfile.read()\n",
|
|
" used_id_list += extract_idlist(texdata)\n",
|
|
"\n",
|
|
"# 去除已使用题号\n",
|
|
"checked_id_list = []\n",
|
|
"ripped_id_list = []\n",
|
|
"for id in id_list:\n",
|
|
" if not id in used_id_list:\n",
|
|
" checked_id_list.append(id)\n",
|
|
" else:\n",
|
|
" ripped_id_list.append(id)\n",
|
|
"\n",
|
|
"print(\"剩余题目数量: \",len(checked_id_list))\n",
|
|
"\n",
|
|
"# 写入文件\n",
|
|
"with open(id_list_file,\"a\",encoding = \"utf8\") as f:\n",
|
|
" f.write(\"\\n\\n\")\n",
|
|
" f.write(\"未使用题号:\\n\")\n",
|
|
" f.write(\",\".join(checked_id_list))\n",
|
|
" f.write(\"\\n\\n已使用题号:\\n\")\n",
|
|
" f.write(\",\".join(ripped_id_list))"
|
|
]
|
|
},
|
|
{
|
|
"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
|
|
}
|