备注信息收集 增加避免重复的校验

This commit is contained in:
wangweiye7840 2024-05-20 14:55:12 +08:00
parent 8010b6db4e
commit 3dc70a2756
1 changed files with 21 additions and 12 deletions

View File

@ -69,19 +69,28 @@ def submit_remarks():
# 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}")
sql = f"SELECT * FROM remarks WHERE ID = %s and remark_content = %s;"
val = (id,f"({category}){remarks}")
print(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)
ret = mycursor.fetchall()
if len(ret) == 0:
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)
else:
mydb.close()
return f"已有备注 ({category}){remarks}"
if __name__ == '__main__':