Add main file
This commit is contained in:
parent
4314dca67d
commit
fc3a3fecf3
3 changed files with 131 additions and 1 deletions
14
CH-Kreuz_7mm.svg
Executable file
14
CH-Kreuz_7mm.svg
Executable file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 20.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg width="7mm" height="7mm" version="1.1" id="Ebene_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 19.8 19.8" style="enable-background:new 0 0 19.8 19.8;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#FFFFFF;}
|
||||
.st1{fill:none;stroke:#FFFFFF;stroke-width:1.4357;stroke-miterlimit:10;}
|
||||
</style>
|
||||
<polygon points="18.3,0.7 1.6,0.7 0.7,0.7 0.7,1.6 0.7,18.3 0.7,19.1 1.6,19.1 18.3,19.1 19.1,19.1 19.1,18.3 19.1,1.6 19.1,0.7 "/>
|
||||
<rect x="8.3" y="4" class="st0" width="3.3" height="11"/>
|
||||
<rect x="4.4" y="7.9" class="st0" width="11" height="3.3"/>
|
||||
<polygon class="st1" points="0.7,1.6 0.7,18.3 0.7,19.1 1.6,19.1 18.3,19.1 19.1,19.1 19.1,18.3 19.1,1.6 19.1,0.7 18.3,0.7
|
||||
1.6,0.7 0.7,0.7 "/>
|
||||
</svg>
|
After Width: | Height: | Size: 903 B |
27
README.md
27
README.md
|
@ -1,3 +1,28 @@
|
|||
# qrr-py
|
||||
|
||||
Erstelle ein vektorisierter QR code für die [QR Rechnung](https://www.einfach-zahlen.ch/de/home/issuer/qr-bill.html).
|
||||
Erstelle ein vektorisierter QR Code für die [QR Rechnung](
|
||||
https://www.einfach-zahlen.ch/de/home/issuer/qr-bill.html).
|
||||
|
||||
Das Programm validiert die txt Datei nicht, sondern schriebt direkt eine
|
||||
SVG Datei daraus.
|
||||
|
||||
|
||||
## Installationsanleitung
|
||||
|
||||
Zuerst müssen Sie Python3 für Ihr Betriebssystem installieren.
|
||||
|
||||
Mit `pip3 install --user qrcode svgutils` können sie sich die
|
||||
notwendigen Pakete herunterladen.
|
||||
|
||||
## Ausführen des Programms
|
||||
|
||||
Mit `python3 qrr.py Rechnung1.txt Rechnung1.svg` wird das Porgramm
|
||||
gestartet.
|
||||
Wenn das Programm keinen Output generiert, so gab es keine Fehler und
|
||||
die SVG Datei sollte erstellt sein.
|
||||
|
||||
# `CH-Kreuz_7mm.svg` Datei
|
||||
Diese Datei ist von [SIX Group AG](
|
||||
https://www.paymentstandards.ch/de/home/software-partner.html) zur
|
||||
Verfügung gestellt. Der direkte Download ist dieser:
|
||||
https://www.paymentstandards.ch/dam/downloads/swiss-cross.zip
|
||||
|
|
91
qrr.py
Executable file
91
qrr.py
Executable file
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os.path
|
||||
import qrcode
|
||||
import qrcode.image.svg
|
||||
import svgutils.transform as st
|
||||
|
||||
|
||||
class qr_rechnung():
|
||||
data = ''
|
||||
error_correction = None
|
||||
|
||||
def __init__(self, data=None, textfile=None):
|
||||
if textfile is not None:
|
||||
self.set_data_from_textfile(textfile)
|
||||
|
||||
def set_data(self, data):
|
||||
self.data = data
|
||||
|
||||
def set_data_from_textfile(self, textfile):
|
||||
with open(textfile, 'r') as f:
|
||||
self.data = f.read()
|
||||
|
||||
def write_file(self, filepath, force=False):
|
||||
global qrcode
|
||||
mode = 'w' if force else 'x'
|
||||
try:
|
||||
assert force or not os.path.isfile(filepath)
|
||||
factory = qrcode.image.svg.SvgPathImage
|
||||
img = qrcode.make(
|
||||
self.data,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
||||
image_factory=qrcode.image.svg.SvgPathImage
|
||||
)
|
||||
img.save(filepath)
|
||||
except AssertionError:
|
||||
print(f"ERROR: Datei {filepath} existiert bereits.")
|
||||
return 1
|
||||
|
||||
qrcode = st.fromfile(filepath)
|
||||
offset = self.calc_move_offset(qrcode.get_size()[0])
|
||||
swisscross = st.fromfile("CH-Kreuz_7mm.svg").getroot()
|
||||
swisscross.moveto(
|
||||
x=offset['offset'],
|
||||
y=offset['offset'],
|
||||
scale_x=offset['scale'],
|
||||
scale_y=offset['scale']
|
||||
)
|
||||
qrcode.append(swisscross)
|
||||
qrcode.save(filepath)
|
||||
|
||||
def calc_move_offset(self, size):
|
||||
org = float(size[:-2])
|
||||
return {
|
||||
'offset': org*0.427935156,
|
||||
'scale': org/137.364857143
|
||||
}
|
||||
|
||||
|
||||
def help(args):
|
||||
return '{0}: Ungültige Eingabe\nAufruf: \
|
||||
{0} TEXTDATEI [SVG-ZIELDATEI]'.format(args[0])
|
||||
|
||||
|
||||
def main(args):
|
||||
try:
|
||||
textfile = args[1]
|
||||
except IndexError:
|
||||
print(help(args))
|
||||
return 1
|
||||
try:
|
||||
svgfile = args[2]
|
||||
except IndexError:
|
||||
try:
|
||||
assert textfile[-4:] == '.txt'
|
||||
svgfile = textfile[:-4]+'.svg'
|
||||
except AssertionError:
|
||||
print(help(args))
|
||||
return 1
|
||||
try:
|
||||
x = qr_rechnung(textfile=textfile)
|
||||
x.write_file(svgfile, force=False)
|
||||
except (PermissionError, FileNotFoundError) as e:
|
||||
print(e)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
sys.exit(main(sys.argv))
|
Loading…
Reference in a new issue