use EAN13 for Drink-Barcodes
Scanner has Problems with Code128. Scanning is not reliable and fast
This commit is contained in:
parent
bf3da33050
commit
55aa6c75af
18
drinks.csv
18
drinks.csv
@ -1,9 +1,9 @@
|
||||
drink,filename
|
||||
KitchenTschunk,tschunk
|
||||
VirginTschunk,vir_tschunk
|
||||
MoscowMule,moscowmule
|
||||
VirginMoscowMule,vir_moscowmule
|
||||
Schnaps2cl,schnaps2cl
|
||||
Schnaps4cl,schnaps4cl
|
||||
Likoer2cl,likoer2cl
|
||||
GinTonic,gintonic
|
||||
code,drink,filename
|
||||
133742000000,KitchenTschunk,tschunk
|
||||
133742000001,VirginTschunk,vir_tschunk
|
||||
133742000002,MoscowMule,moscowmule
|
||||
133742000003,VirginMoscowMule,vir_moscowmule
|
||||
133742000004,Schnaps2cl,schnaps2cl
|
||||
133742000005,Schnaps4cl,schnaps4cl
|
||||
133742000006,Likoer2cl,likoer2cl
|
||||
133742000007,GinTonic,gintonic
|
||||
|
|
33
main.py
33
main.py
@ -1,6 +1,6 @@
|
||||
import csv
|
||||
import os
|
||||
from barcode import Code128
|
||||
from barcode import Code128, EAN13
|
||||
from barcode.writer import ImageWriter
|
||||
from fpdf import FPDF
|
||||
|
||||
@ -13,18 +13,25 @@ pdf = FPDF()
|
||||
pdf_row = 0
|
||||
pdf_colum = 0
|
||||
|
||||
def generate_barcode(filename, content):
|
||||
def generate_barcode(filename, content, label):
|
||||
if not os.path.exists('out'):
|
||||
os.makedirs('out')
|
||||
|
||||
with open('out/' + filename + '.png', "wb") as f:
|
||||
EAN13.default_writer_options['write_text'] = False
|
||||
EAN13.default_writer_options['text'] = label
|
||||
EAN13(str(content), writer=ImageWriter()).write(f)
|
||||
|
||||
|
||||
def generate_barcode_username(filename, content, label):
|
||||
if not os.path.exists('out'):
|
||||
os.makedirs('out')
|
||||
|
||||
with open('out/' + filename + '.png', "wb") as f:
|
||||
Code128.default_writer_options['write_text'] = False
|
||||
Code128.default_writer_options['text'] = label
|
||||
Code128(str(content), writer=ImageWriter()).write(f)
|
||||
|
||||
|
||||
def generate_barcode_username(filename, content):
|
||||
generate_barcode(filename, content + '\t') # we need a tab-character to select the 'strichliste'
|
||||
|
||||
|
||||
def pdf_add_barcode(imagepath):
|
||||
global pdf_row, pdf_colum, pdf_row_spacing
|
||||
|
||||
@ -51,7 +58,7 @@ def pdf_add_barcode(imagepath):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
generate_barcode_username('raven', 'raven')
|
||||
generate_barcode_username('raven\t', 'raven', 'raven')
|
||||
|
||||
pdf.add_page()
|
||||
pdf.set_font("Arial", size=15)
|
||||
@ -61,9 +68,13 @@ if __name__ == '__main__':
|
||||
datareader = csv.reader(csvfile)
|
||||
next(datareader, None) # skip the headers
|
||||
for row in datareader:
|
||||
print('Generating Code for:', row[0], 'to', row[1])
|
||||
generate_barcode(row[1], row[0])
|
||||
pdf_add_barcode('out/' + row[1] + '.png')
|
||||
row_code = row[0]
|
||||
row_text = row[1]
|
||||
row_filename = row[2]
|
||||
|
||||
print('Generating Code for:', row_text, 'row_filename', row_filename, 'row_code', row_code)
|
||||
generate_barcode(row_filename, row_code, row_text)
|
||||
pdf_add_barcode('out/' + row_filename + '.png')
|
||||
|
||||
pdf.output("out/barcodes.pdf")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user