You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
|
1 week ago
|
import sqlite3
|
||
|
|
import pymysql
|
||
|
|
|
||
|
|
show_start_time = '2021-03-08 15:10:00' # 场次开始时间
|
||
|
|
qrcode = '11051401' # 当前默认的qrcode
|
||
|
|
|
||
|
|
# 初始化sqlite数据库
|
||
|
|
sqlite_conn = sqlite3.connect('database.db')
|
||
|
|
sqlite_cursor = sqlite_conn.cursor()
|
||
|
|
|
||
|
|
# r = cursor.execute('SELECT * FROM qrcode;')
|
||
|
|
# print(r.fetchall())
|
||
|
|
|
||
|
|
# 写入数据
|
||
|
|
# with open(r"C:\Users\roger\Desktop\qrcode.txt", 'r', encoding='utf-8') as f:
|
||
|
|
# lines = f.readlines()
|
||
|
|
# for l in lines:
|
||
|
|
# cursor.execute('INSERT INTO qrcode (qrcode) VALUES (?);', (l,))
|
||
|
|
# conn.commit()
|
||
|
|
|
||
|
|
|
||
|
|
# 初始化Mysql数据库
|
||
|
|
d = {
|
||
|
|
'host': '192.168.55.99',
|
||
|
|
'user': 'dbadmin',
|
||
|
|
'password': 'fXMSR37mLP7w88ji',
|
||
|
|
'database': 'cine',
|
||
|
|
}
|
||
|
|
|
||
|
|
# 替换QRcode数据
|
||
|
|
test_data = (show_start_time, qrcode)
|
||
|
|
|
||
|
|
mysql_conn = pymysql.connect(**d)
|
||
|
|
mysql_cursor = mysql_conn.cursor(cursor=pymysql.cursors.DictCursor)
|
||
|
|
mysql_cursor.execute(
|
||
|
|
'SELECT * FROM cinema_sell_log WHERE cinema_movie_show_start_time = %s and cinema_ticket_qrcode = %s;', test_data)
|
||
|
|
all_ticket_data = mysql_cursor.fetchall()
|
||
|
|
print(all_ticket_data)
|
||
|
|
data_len = len(all_ticket_data)
|
||
|
|
|
||
|
|
qrcode_list = sqlite_cursor.execute('SELECT * FROM qrcode WHERE used = "No" LIMIT ?;', (data_len,)).fetchall()
|
||
|
|
print(qrcode_list)
|
||
|
|
|
||
|
|
for t in all_ticket_data:
|
||
|
|
qrcode_item = qrcode_list[all_ticket_data.index(t)]
|
||
|
|
qrcode_id = qrcode_item[0]
|
||
|
|
qrcode = qrcode_item[1][:-1]
|
||
|
|
print(qrcode)
|
||
|
|
mysql_cursor.execute('UPDATE cinema_sell_log SET cinema_ticket_qrcode = %s WHERE cinema_sell_id = %s;',
|
||
|
|
(qrcode, t['cinema_sell_id']))
|
||
|
|
sqlite_cursor.execute('UPDATE qrcode SET used = "Yes" WHERE id = ?;', (qrcode_id,))
|
||
|
|
mysql_conn.commit()
|
||
|
|
sqlite_conn.commit()
|
||
|
|
|
||
|
|
mysql_cursor.close()
|
||
|
|
sqlite_cursor.close()
|
||
|
|
mysql_conn.close()
|
||
|
|
sqlite_conn.close()
|