ich habe hier einen code, mit dem qr-codes in eine sql-datenbank gespeichert werden können(glaub ich

Code: Alles auswählen
desktopFile = os.path.expanduser("~\Desktop")
path_grund = desktopFile+'\\Probeordner\\SYSTEM'
folderpath = path_grund+'\\QR-Codes'
path_qr = path_grund+'\\QR-Datenbank'
try:
os.makedirs(path_qr)
os.makedirs(folderpath)
except:
pass
qr_text = self.qrPhotoTxt.GetValue()
qr = qrcode.QRCode(version=1, box_size=10, border=4)
qr.add_data(self.qrDataTxt.GetValue())
qr.make(fit=True)
x = qr.make_image()
qr_file = os.path.join(folderpath, self.qrPhotoTxt.GetValue() + ".png")
img_file = open(qr_file, 'wb')
x.save(img_file, 'PNG')
img_file.close()
with open(qr_file, 'rb') as input_file:
ablob = input_file.read()
base=os.path.basename(qr_file)
afile, ext = os.path.splitext(base)
SQL_QR = '%s\\QR_Codes.db' %(path_qr)
conn = sqlite3.connect(SQL_QR)
cursor = conn.cursor()
sql = '''CREATE TABLE IF NOT EXISTS QR_Codes(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
PICTURE BLOB,
TYPE TEXT,
FILE_NAME TEXT);'''
conn.execute(sql)
sql = '''INSERT INTO QR_Codes
(PICTURE, TYPE, FILE_NAME)
VALUES(?, ?, ?);'''
conn.execute(sql,[sqlite3.Binary(ablob), ext, afile])
conn.commit()
sql = "SELECT PICTURE, TYPE, FILE_NAME FROM QR_Codes WHERE FILE_NAME = :FILE_NAME"
param = {'FILE_NAME': afile}
cursor.execute(sql, param)
ablob, ext, afile = cursor.fetchone()
filename = afile + ext
with open(filename, 'wb') as output_file:
output_file.write(ablob)
conn.close()
self.showQRCode(qr_file)
Code: Alles auswählen
img_file = open(qr_file, 'wb')
x.save(img_file, 'PNG')
img_file.close()
geht das auch?
sonst ist es ja doppelt gespeichert
