98 lines
3.0 KiB
Plaintext
98 lines
3.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"正在生成: 高三下学期周末卷04答案\n",
|
|
"0\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os,re,json\n",
|
|
"\n",
|
|
"# filename = r\"C:\\Users\\weiye\\Documents\\wwy sync\\23届\\第二轮复习讲义\\09_立体几何综合.tex\"\n",
|
|
"filelist = [r\"C:\\Users\\weiye\\Documents\\wwy sync\\23届\\下学期周末卷\\高三下学期周末卷04.tex\",\n",
|
|
"\n",
|
|
"]\n",
|
|
"pdf_dir = \"临时文件\"\n",
|
|
"\n",
|
|
"for filename in filelist:\n",
|
|
" outfilename = os.path.split(filename)[1][:-4]+\"答案\"\n",
|
|
" print(\"正在生成: \",outfilename)\n",
|
|
" with open(filename,\"r\",encoding = \"u8\") as f:\n",
|
|
" data = f.read()\n",
|
|
" with open(\"../题库0.3/Problems.json\",\"r\",encoding = \"u8\") as f:\n",
|
|
" pro_dict = json.loads(f.read())\n",
|
|
"\n",
|
|
" ids = re.findall(r\"\\((\\d{6})\\)\",data)\n",
|
|
"\n",
|
|
" output_data = \"\"\n",
|
|
" for id in ids:\n",
|
|
" problemset = pro_dict[id]\n",
|
|
" content = problemset[\"content\"]\n",
|
|
" solution = problemset[\"solution\"]\n",
|
|
" answer = \"\\\\textcolor{red}{\" + (problemset[\"ans\"] if problemset[\"ans\"] != \"\" else \"\\\\textcolor{blue}{暂无答案}\") + \"}\"\n",
|
|
" output_data += \"\\\\item \" + \"(\"+id+\") \" + content + \"\\n\\n\" + \"答案: \" + answer + \"\\n\\n\" \n",
|
|
"\n",
|
|
" with open(\"模板文件/日常选题讲义模板.txt\",\"r\",encoding = \"u8\") as f:\n",
|
|
" outlatex = f.read()\n",
|
|
"\n",
|
|
" outlatex = outlatex.replace(\"待替换1\",output_data)\n",
|
|
" outlatex = outlatex.replace(\"标题文字待处理\",outfilename)\n",
|
|
"\n",
|
|
" outfile = os.path.join(\"临时文件\",outfilename+\".tex\")\n",
|
|
" with open(outfile,\"w\",encoding=\"u8\") as f:\n",
|
|
" f.write(outlatex)\n",
|
|
"\n",
|
|
" outfile = outfile.replace(\"\\\\\",\"/\")\n",
|
|
"\n",
|
|
" os.system(\"xelatex -interaction=batchmode -output-directory=\" + pdf_dir + \" \"+ outfile)\n",
|
|
" print(os.system(\"xelatex -interaction=batchmode -output-directory=\" + pdf_dir + \" \"+ outfile))\n",
|
|
"\n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "pythontest",
|
|
"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.15"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "91219a98e0e9be72efb992f647fe78b593124968b75db0b865552d6787c8db93"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|