From 5f60529a0e97544cce273794d4e2f37638d4f4ee Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 12 May 2024 16:57:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E6=B3=A8=E6=94=B6=E9=9B=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=B7=B2=E8=83=BD=E6=AD=A3=E7=A1=AE=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E5=9B=BE=E7=89=87(=E9=95=BF=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=E5=8F=AA=E6=9C=89=E7=AC=AC=E4=B8=80=E9=A1=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/templates/show_image.html | 8 +++++++- 工具v4/备注信息收集.py | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/工具v4/templates/show_image.html b/工具v4/templates/show_image.html index 782952f3..c28c8a21 100644 --- a/工具v4/templates/show_image.html +++ b/工具v4/templates/show_image.html @@ -2,6 +2,12 @@ 输入备注 +

输入备注

@@ -12,7 +18,7 @@

diff --git a/工具v4/备注信息收集.py b/工具v4/备注信息收集.py index b97ef48f..9df7d158 100644 --- a/工具v4/备注信息收集.py +++ b/工具v4/备注信息收集.py @@ -1,5 +1,6 @@ from flask import Flask, render_template, request, redirect, url_for -import os +import os,shutil +from database_tools_2 import * app = Flask(__name__) @@ -10,10 +11,27 @@ def index(): @app.route('/show_image', methods=['POST']) def show_image(): if request.method == 'POST': - global question_number - question_number = request.form['question_number'] + id = request.form['question_number'].zfill(6) + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku") + mycursor = mydb.cursor() + sql = "SELECT content FROM problems WHERE ID = %s;" + val = (id,) + mycursor.execute(sql,val) + content = mycursor.fetchall()[0][0] + mydb.close() + latex_raw = ReadTextFile("模板文件/独立文件模板.txt") + latexdata = StringSubstitute(r"<<待替换\d*>>",latex_raw,[content]) + makedir("临时文件/pics") + currentdate = GetDate() + currenttime = GetTime() + SaveTextFile(latexdata,f"临时文件/pics/ID{id}-{currentdate}-{currenttime}.tex") + os.system(f"xelatex -interaction=batchmode -output-directory=临时文件/pics ID{id}-{currentdate}-{currenttime}.tex") + os.chdir("临时文件/pics") + os.system(f"pdftocairo -png -r 600 ID{id}-{currentdate}-{currenttime}.pdf") + os.chdir("../..") + shutil.copy(f"临时文件/pics/ID{id}-{currentdate}-{currenttime}-1.png",f"static/{id}.png") - return render_template('show_image.html', image_path=f'/static/{question_number}.png') + return render_template('show_image.html', image_path=f'/static/{id}.png') @app.route('/submit_remarks', methods=['POST']) def submit_remarks():