20220914 evening

This commit is contained in:
weiye.wang 2022-09-14 21:33:33 +08:00
parent 236763c691
commit db4647c5a9
2 changed files with 190 additions and 0 deletions

View File

@ -0,0 +1,76 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import zipfile,os\n",
"from PIL import Image\n",
"\n",
"#设置工作目录其中放小闲下载的错题zip文件\n",
"working_path = r\"临时文件/错题处理\"\n",
"os.chdir(working_path)\n",
"\n",
"for zips in [f for f in os.listdir() if \".zip\" in f]:\n",
" print(\"正在处理:\",zips)\n",
" zf = zipfile.ZipFile(zips)\n",
" picture_list = [f.filename for f in zf.filelist if \".png\" in f.filename]\n",
" total_width = 0\n",
" total_height = 0\n",
" for p in picture_list:\n",
" picture_file = zf.extract(p)\n",
" current_pic = Image.open(picture_file)\n",
" if total_width < current_pic.width:\n",
" total_width = current_pic.width\n",
" total_height += current_pic.height\n",
" current_pic.close()\n",
" canvas = Image.new(\"RGB\",(total_width,total_height),color=(255,255,255))\n",
" position = 0\n",
" for p in picture_list:\n",
" current_pic = Image.open(p)\n",
" canvas.paste(current_pic,(0,position))\n",
" position += current_pic.height\n",
" current_pic.close()\n",
" os.remove(p)\n",
" zf.close()\n",
" canvas.save(zips[:-4]+\".png\")"
]
},
{
"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
}

View File

@ -0,0 +1,114 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 填空题 1\n",
"2 选择题 1\n",
"3 解答题 1\n",
"4 解答题 1\n",
"5 填空题 1\n",
"6 填空题 4\n",
"7 解答题 1\n",
"8 解答题 1\n",
"9 填空题 1\n",
"10 填空题 3\n",
"11 解答题 3\n",
"12 解答题 1\n",
"13 解答题 1\n",
"14 解答题 1\n",
"15 解答题 1\n",
"16 填空题 3\n",
"17 解答题 1\n",
"18 解答题 3\n",
"19 解答题 1\n",
"20 填空题 1\n",
"21 填空题 1\n",
"1 选择题 1\n",
"2 解答题 3\n",
"3 填空题 1\n",
"4 填空题 1\n",
"5 解答题 1\n",
"6 填空题 1\n",
"7 选择题 1\n",
"8 解答题 1\n",
"9 解答题 1\n",
"10 解答题 1\n",
"11 解答题 1\n",
"12 填空题 1\n",
"13 解答题 4\n",
"14 填空题 1\n",
"15 解答题 1\n",
"16 解答题 3\n"
]
}
],
"source": [
"import os,re\n",
"#修改文件名\n",
"filename = r\"C:\\Users\\weiye\\Documents\\wwy sync\\23届\\第一轮复习讲义\\11_三角比的定义及直接性质.tex\"\n",
"outputfile = \"临时文件/题目状态.txt\"\n",
"\n",
"outputstr = \"\"\n",
"with open(filename,\"r\",encoding = \"utf8\") as f:\n",
" data = f.read()\n",
"sections = re.findall(r\"\\\\begin\\{enumerate\\}([\\s\\S]*?\\\\end\\{enumerate\\})\",data)\n",
"for sec in sections:\n",
" sec = sec.replace(\"\\\\item\",\"\\\\enditem\\\\item\").replace(\"\\\\end{enumerate}\",\"\\\\enditem\")\n",
" problems = re.findall(r\"\\\\item([\\s\\S]*?)\\\\enditem\",sec)\n",
" count = 0\n",
" for p in problems:\n",
" count += 1\n",
" if \"\\\\bracket\" in p:\n",
" genre = \"选择题\"\n",
" parts = len(re.findall(r\"\\\\bracket\",p))\n",
" elif \"\\\\blank\" in p:\n",
" genre = \"填空题\"\n",
" parts = len(re.findall(r\"\\\\blank\",p))\n",
" else:\n",
" genre = \"解答题\"\n",
" parts = len(re.findall(r\"\\([\\d]{1,2}\\)\",p))\n",
" if parts == 0:\n",
" parts = 1\n",
" print(count,genre,parts)\n",
" outputstr += str(count) + \"-\" + genre + \"-\" + str(parts) + \"\\n\"\n",
" outputstr += \"\\n\"\n",
"with open(outputfile,\"w\",encoding = \"utf8\") as f:\n",
" f.write(outputstr)"
]
}
],
"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
}