This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具/生成文件夹下的题号清单.ipynb

147 lines
3.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2021届杨浦区基础考.tex\n",
"填空题\n",
"(011988)\n",
"(011989)\n",
"(011990)\n",
"(011991)\n",
"(011992)\n",
"(011993)\n",
"(011994)\n",
"(011995)\n",
"(011996)\n",
"(011997)\n",
"(011998)\n",
"(011999)\n",
"选择题\n",
"(012000)\n",
"(012001)\n",
"(012002)\n",
"(012003)\n",
"解答题\n",
"(012004)\n",
"(012005)\n",
"(012006)\n",
"(012007)\n",
"(012008)\n",
"\n",
"\n",
"\n",
"2022届杨浦区基础考.tex\n",
"填空题\n",
"(012009)\n",
"(012010)\n",
"(012011)\n",
"(012012)\n",
"(012013)\n",
"(012014)\n",
"(012015)\n",
"(012016)\n",
"(012017)\n",
"(012018)\n",
"(012019)\n",
"(012020)\n",
"选择题\n",
"(012021)\n",
"(012022)\n",
"(012023)\n",
"(012024)\n",
"解答题\n",
"(012025)\n",
"(012026)\n",
"(012027)\n",
"(012028)\n",
"(012029)\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"import os,re\n",
"\"---此处输入文件夹名---\"\n",
"directory = r\"C:\\Users\\weiye\\Documents\\wwy sync\\23届\\其他讲义与试卷\"\n",
"\"---文件夹名输入结束---\"\n",
"\n",
"filelist = [filename for filename in os.listdir(directory) if \".tex\" in filename]\n",
"\n",
"output = \"\"\n",
"\n",
"for filename in filelist:\n",
" print(filename)\n",
" output += filename + \"\\n\"\n",
" with open(os.path.join(directory,filename),\"r\",encoding = \"u8\") as f:\n",
" try:\n",
" data = re.findall(r\"\\\\begin{document}([\\s\\S]*?)\\\\end{document}\",f.read())[0]\n",
" data = data.replace(r\"\\section\",\"endsecbeginsec\") + \"endsec\"\n",
" sectionlist = re.findall(r\"beginsec([\\s\\S]*?)endsec\",data)\n",
" for sec in sectionlist:\n",
" secname = re.findall(r\"{([\\S]*)}\",sec)[0]\n",
" output += secname + \"\\n\"\n",
" print(secname)\n",
" for id in re.findall(r\"\\(\\d{6}\\)\",sec):\n",
" print(id)\n",
" output += id + \"\\n\"\n",
" except:\n",
" pass \n",
" output += \"\\n\\n\"\n",
" print(\"\\n\\n\")\n",
"\n",
"with open(os.path.join(directory,\"题号清点.txt\"),\"w\",encoding = \"u8\") as f:\n",
" f.write(output + \"\\n\\n\\n以下题号不含括号\\n\\n\\n\" + output.replace(\"(\",\"\").replace(\")\",\"\"))\n",
"\n",
" \n",
"\n",
"\n",
" \n",
" \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
}