diff --git a/工具v4/templates/remarkindex.html b/工具v4/templates/remarkindex.html
index b7d0b0ac..3e0be84f 100644
--- a/工具v4/templates/remarkindex.html
+++ b/工具v4/templates/remarkindex.html
@@ -1,25 +1,17 @@
- Save Data
+ 登记备注
-
\ No newline at end of file
diff --git a/工具v4/备注信息收集.py b/工具v4/备注信息收集.py
index edfebc3c..4846bf0b 100644
--- a/工具v4/备注信息收集.py
+++ b/工具v4/备注信息收集.py
@@ -6,11 +6,16 @@ app = Flask(__name__)
@app.route('/')
def index():
- return render_template('index.html')
+ return render_template('remarkindex.html')
@app.route('/show_image', methods=['POST'])
def show_image():
if request.method == 'POST':
+ global id,username
+ username = request.form['username'].strip()
+ print(username)
+ if len(username) <= 1:
+ return "姓名有误."
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()
@@ -21,7 +26,7 @@ def show_image():
sql = "SELECT date,remark_content FROM remarks WHERE ID = %s;"
mycursor.execute(sql,val)
remark_list = sorted(mycursor.fetchall(),key=lambda item:item[0],reverse=True)
- print(remark_list)
+ # print(remark_list)
mydb.close()
content_hash = hashlib.sha256(content.encode("utf8")).hexdigest()
# print(content_hash,type(content_hash))
@@ -59,14 +64,25 @@ def show_image():
@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()
+ remarks = request.form['remarks'].repalce("\n"," ").strip()
+ date = GetDate()
+ # mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tikutest")
+ mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku")
+ mycursor = mydb.cursor()
+ sql = f"INSERT INTO remarks SET ID = %s, date = %s, remark_content = %s;"
+ val = (id,date,f"({category}){remarks}")
+ mycursor.execute(sql,val)
+ ip_address = request.headers.get('X-Forwarded-For', request.remote_addr)
+ # 如果 X-Forwarded-For 头存在多个 IP 地址,则取第一个
+ if ',' in ip_address:
+ ip_address = ip_address.split(',')[0]
+ sql = "INSERT INTO logs (DATE,TIME,username,ID,action,db_content) VALUE (%s,%s,%s,%s,%s,%s);"
+ val = (GetDate(),GetTime(),f"{username} at {ip_address}",id,f"网页新增备注",f"({category}){remarks}")
+ mycursor.execute(sql,val)
+ mydb.commit()
+ 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
+ app.run(host = "0.0.0.0", port = 25433)
\ No newline at end of file