From b17f89c466123b6e1dac98c63a0667c2a8af95eb Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 12 May 2024 18:51:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=97=E5=88=B0=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=BC=98=E5=8C=96,=20=E5=B7=B2=E6=9C=89?= =?UTF-8?q?=E7=9A=84=E5=9B=BE=E7=89=87=E9=AA=8C=E8=AF=81sha256=E5=90=8E?= =?UTF-8?q?=E5=8F=AF=E5=A4=8D=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/templates/show_image.html | 2 +- 工具v4/备注信息收集.py | 47 +++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/工具v4/templates/show_image.html b/工具v4/templates/show_image.html index c28c8a21..cfbcbcc8 100644 --- a/工具v4/templates/show_image.html +++ b/工具v4/templates/show_image.html @@ -4,7 +4,7 @@ 输入备注 diff --git a/工具v4/备注信息收集.py b/工具v4/备注信息收集.py index 9df7d158..784bb305 100644 --- a/工具v4/备注信息收集.py +++ b/工具v4/备注信息收集.py @@ -1,5 +1,5 @@ from flask import Flask, render_template, request, redirect, url_for -import os,shutil +import os,shutil,hashlib from database_tools_2 import * app = Flask(__name__) @@ -19,25 +19,46 @@ def show_image(): 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") - + content_hash = hashlib.sha256(content.encode("utf8")).hexdigest() + # print(content_hash,type(content_hash)) + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tikupics") + mycursor = mydb.cursor() + mycursor.execute("SELECT hash,pic FROM pics WHERE ID = %s;",(id,)) + ret_list = mycursor.fetchall() + if len(ret_list) > 0 and ret_list[0][0] == content_hash: + with open(f"static/{id}.png","wb") as f: + f.write(ret_list[0][1]) + else: + 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") + with open(f"static/{id}.png","rb") as f: + image_data = f.read() + mycursor.execute("INSERT INTO pics (ID,pic,date,hash) VALUES (%s,%s,%s,%s)",(id,image_data,currentdate,content_hash)) + mydb.commit() + mydb.close() return render_template('show_image.html', image_path=f'/static/{id}.png') + @app.route('/submit_remarks', methods=['POST']) def submit_remarks(): category = request.form['category'] remarks = request.form['remarks'] + # date = GetDate() + # mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku") + # mycursor = mydb.cursor() + + # mydb.close() return render_template('show_remarks.html', category=category, remarks=remarks) + if __name__ == '__main__': app.run(debug=True) \ No newline at end of file