{ "cells": [ { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "周末卷01.tex\n", "填空题\n", "(010923)\n", "(010924)\n", "(010925)\n", "(010926)\n", "(030013)\n", "(010928)\n", "(010929)\n", "(010930)\n", "(030014)\n", "(010932)\n", "(010933)\n", "(010934)\n", "选择题\n", "(010935)\n", "(010936)\n", "(010937)\n", "(010938)\n", "解答题\n", "(010939)\n", "(010940)\n", "(010941)\n", "(010942)\n", "(010943)\n", "\n", "\n", "\n", "周末卷02.tex\n", "填空题\n", "(010944)\n", "(030017)\n", "(010946)\n", "(010947)\n", "(010948)\n", "(010949)\n", "(010950)\n", "(010951)\n", "(010952)\n", "(010953)\n", "(010954)\n", "(010955)\n", "选择题\n", "(010956)\n", "(002874)\n", "(010958)\n", "(010959)\n", "解答题\n", "(010960)\n", "(010961)\n", "(010962)\n", "(010963)\n", "(010964)\n", "\n", "\n", "\n", "周末卷03.tex\n", "填空题\n", "(003115)\n", "(006264)\n", "(003096)\n", "(001472)\n", "(006604)\n", "(030027)\n", "(030028)\n", "选择题\n", "(006305)\n", "解答题\n", "(006460)\n", "(006463)\n", "\n", "\n", "\n", "周末卷03_暂未使用.tex\n", "填空题\n", "(010965)\n", "(010966)\n", "(030023)\n", "(010968)\n", "(010969)\n", "(010970)\n", "(030025)\n", "(010972)\n", "(030024)\n", "(010974)\n", "(010975)\n", "(010976)\n", "选择题\n", "(010977)\n", "(002745)\n", "(010979)\n", "(010980)\n", "解答题\n", "(010981)\n", "(010982)\n", "(010983)\n", "(010984)\n", "(010985)\n", "\n", "\n", "\n", "周末卷04.tex\n", "填空题\n", "(001853)\n", "(030108)\n", "(003355)\n", "(000655)\n", "(000724)\n", "(001860)\n", "(002038)\n", "(030106)\n", "(030107)\n", "(003621)\n", "选择题\n", "(001846)\n", "(002013)\n", "(003703)\n", "解答题\n", "(001557)\n", "(004702)\n", "\n", "\n", "\n", "周末卷05.tex\n", "填空题\n", "(030169)\n", "(030273)\n", "(001677)\n", "(003531)\n", "(003533)\n", "(003455)\n", "选择题\n", "(004092)\n", "(003891)\n", "(001643)\n", "解答题\n", "(000182)\n", "(000187)\n", "(000298)\n", "(003495)\n", "(004180)\n", "(003500)\n", "(003462)\n", "\n", "\n", "\n", "周末卷06.tex\n", "填空题\n", "(010497)\n", "(010501)\n", "(001726)\n", "(030279)\n", "(030280)\n", "(030278)\n", "(001631)\n", "(001668)\n", "(001724)\n", "选择题\n", "(001676)\n", "(010487)\n", "(009998)\n", "(010491)\n", "解答题\n", "(010470)\n", "(010533)\n", "(010508)\n", "(010000)\n", "\n", "\n", "\n", "周末卷07.tex\n", "填空题\n", "(004446)\n", "(004447)\n", "(004448)\n", "(004449)\n", "(004450)\n", "(004451)\n", "(004453)\n", "(004454)\n", "(004455)\n", "(004456)\n", "(004457)\n", "选择题\n", "(004458)\n", "解答题\n", "(004462)\n", "(004463)\n", "(004464)\n", "\n", "\n", "\n", "国庆卷.tex\n", "课前练习\n", "(030033)\n", "(030030)\n", "(030032)\n", "(030031)\n", "(030029)\n", "(030034)\n", "(030076)\n", "(030036)\n", "(030037)\n", "(030039)\n", "(030044)\n", "(030038)\n", "(030040)\n", "(030041)\n", "(030045)\n", "(030042)\n", "(030048)\n", "(030046)\n", "(030047)\n", "(030051)\n", "(030043)\n", "(030052)\n", "(030050)\n", "(030049)\n", "(030053)\n", "(030054)\n", "(030055)\n", "(030059)\n", "(030058)\n", "(030056)\n", "(030057)\n", "(030060)\n", "(030061)\n", "(030063)\n", "(030062)\n", "(030065)\n", "(030067)\n", "(030066)\n", "(030064)\n", "(030068)\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 }