init
This commit is contained in:
commit
bf3da33050
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
bin
|
||||||
|
lib
|
||||||
|
.idea
|
||||||
|
out
|
9
drinks.csv
Normal file
9
drinks.csv
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
drink,filename
|
||||||
|
KitchenTschunk,tschunk
|
||||||
|
VirginTschunk,vir_tschunk
|
||||||
|
MoscowMule,moscowmule
|
||||||
|
VirginMoscowMule,vir_moscowmule
|
||||||
|
Schnaps2cl,schnaps2cl
|
||||||
|
Schnaps4cl,schnaps4cl
|
||||||
|
Likoer2cl,likoer2cl
|
||||||
|
GinTonic,gintonic
|
|
72
main.py
Normal file
72
main.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import csv
|
||||||
|
import os
|
||||||
|
from barcode import Code128
|
||||||
|
from barcode.writer import ImageWriter
|
||||||
|
from fpdf import FPDF
|
||||||
|
|
||||||
|
# options
|
||||||
|
code_height = 40
|
||||||
|
pdf_row_spacing = 40
|
||||||
|
|
||||||
|
# internal stuff
|
||||||
|
pdf = FPDF()
|
||||||
|
pdf_row = 0
|
||||||
|
pdf_colum = 0
|
||||||
|
|
||||||
|
def generate_barcode(filename, content):
|
||||||
|
if not os.path.exists('out'):
|
||||||
|
os.makedirs('out')
|
||||||
|
|
||||||
|
with open('out/' + filename + '.png', "wb") as f:
|
||||||
|
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
|
||||||
|
|
||||||
|
# determine y-position
|
||||||
|
y = 10 + (pdf_row * pdf_row_spacing)
|
||||||
|
|
||||||
|
if y >= 251:
|
||||||
|
print('maximum Code per Page reached. Creating new Page.')
|
||||||
|
print('y: ' + str(y) + ' pdf_row: ' + str(pdf_row))
|
||||||
|
y = 10
|
||||||
|
pdf_row = 0
|
||||||
|
pdf.add_page()
|
||||||
|
|
||||||
|
# determine x-position
|
||||||
|
if pdf_colum == 0:
|
||||||
|
x = 10
|
||||||
|
pdf_colum += 1
|
||||||
|
else:
|
||||||
|
x = 100
|
||||||
|
pdf_colum = 0 # reset colum
|
||||||
|
pdf_row += 1 # start a new row
|
||||||
|
|
||||||
|
pdf.image(imagepath, x=x, y=y, h=code_height)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
generate_barcode_username('raven', 'raven')
|
||||||
|
|
||||||
|
pdf.add_page()
|
||||||
|
pdf.set_font("Arial", size=15)
|
||||||
|
|
||||||
|
filename = 'drinks.csv'
|
||||||
|
with open(filename, 'r') as csvfile:
|
||||||
|
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')
|
||||||
|
|
||||||
|
pdf.output("out/barcodes.pdf")
|
||||||
|
|
||||||
|
print()
|
||||||
|
print('drink responsibly and')
|
||||||
|
print('Don\'t drink and root!')
|
8
pyvenv.cfg
Normal file
8
pyvenv.cfg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
home = /opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10
|
||||||
|
implementation = CPython
|
||||||
|
version_info = 3.10.9.final.0
|
||||||
|
virtualenv = 20.13.0
|
||||||
|
include-system-site-packages = false
|
||||||
|
base-prefix = /opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10
|
||||||
|
base-exec-prefix = /opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10
|
||||||
|
base-executable = /opt/homebrew/bin/python3.10
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
python-barcode
|
||||||
|
python-barcode[images]
|
||||||
|
fpdf
|
Loading…
Reference in New Issue
Block a user