Umlaute works now. Verified on https://www.swiss-qr-invoice.org/validator/
This commit is contained in:
parent
308ccd5a6c
commit
2481e01e26
4 changed files with 109 additions and 19 deletions
31
Beispiel.txt
Normal file
31
Beispiel.txt
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
SPC
|
||||||
|
0200
|
||||||
|
1
|
||||||
|
CH2480808009320210528
|
||||||
|
S
|
||||||
|
Jäckle Data Management GmbH
|
||||||
|
Rodelstrasse
|
||||||
|
39
|
||||||
|
8266
|
||||||
|
Steckborn
|
||||||
|
CH
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CHF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NON
|
||||||
|
|
||||||
|
Spende an die Entwickler von qrr.py
|
||||||
|
EPD
|
10
README.md
10
README.md
|
@ -12,9 +12,15 @@ SVG Datei daraus.
|
||||||
Zuerst müssen Sie [Python3](https://www.python.org/)
|
Zuerst müssen Sie [Python3](https://www.python.org/)
|
||||||
für Ihr Betriebssystem installieren.
|
für Ihr Betriebssystem installieren.
|
||||||
|
|
||||||
Mit `pip3 install --user qrcode svgutils cairosvg` können sie sich die
|
Mit `pip3 install --user qrcode svgutils chardet` können sie sich die
|
||||||
notwendigen Pakete herunterladen.
|
notwendigen Pakete herunterladen.
|
||||||
|
|
||||||
|
Für die Cario Version `qrr.cario.py` muss auch
|
||||||
|
`pip3 install --user cairosvg`
|
||||||
|
installiert werden. Diese Version kann die QR Rechunung als png oder pdf
|
||||||
|
exportieren.
|
||||||
|
|
||||||
|
|
||||||
## Ausführen des Programms
|
## Ausführen des Programms
|
||||||
|
|
||||||
Mit `python3 qrr.py Rechnung1.txt Rechnung1.svg` wird das Porgramm
|
Mit `python3 qrr.py Rechnung1.txt Rechnung1.svg` wird das Porgramm
|
||||||
|
@ -22,7 +28,9 @@ gestartet.
|
||||||
Wenn das Programm keinen Output generiert, so gab es keine Fehler und
|
Wenn das Programm keinen Output generiert, so gab es keine Fehler und
|
||||||
die SVG Datei sollte erstellt sein.
|
die SVG Datei sollte erstellt sein.
|
||||||
|
|
||||||
|
|
||||||
# CH-Kreuz
|
# CH-Kreuz
|
||||||
|
|
||||||
Diese Graphik ist von [SIX Group AG](
|
Diese Graphik ist von [SIX Group AG](
|
||||||
https://www.paymentstandards.ch/de/home/software-partner.html) zur
|
https://www.paymentstandards.ch/de/home/software-partner.html) zur
|
||||||
Verfügung gestellt. Der direkte Download ist dieser:
|
Verfügung gestellt. Der direkte Download ist dieser:
|
||||||
|
|
62
qrr.cairo.py
Executable file
62
qrr.cairo.py
Executable file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from cairosvg import (svg2pdf, svg2png)
|
||||||
|
from qrr import qr_rechnung
|
||||||
|
|
||||||
|
def help(args):
|
||||||
|
return '\n'.join([
|
||||||
|
'{0}: Ungültige Eingabe',
|
||||||
|
'Aufruf: {0} TEXTDATEI [SVG-ZIELDATEI]',
|
||||||
|
'Alternativ kann die ZIELDATEI auch mit .pdf oder .png enden.'
|
||||||
|
]).format(args[0])
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
try:
|
||||||
|
textfile = args[1]
|
||||||
|
except IndexError:
|
||||||
|
print(help(args))
|
||||||
|
return 1
|
||||||
|
try:
|
||||||
|
output_format = 'svg'
|
||||||
|
svgfile = args[2]
|
||||||
|
if svgfile[-4:] == '.svg':
|
||||||
|
pass
|
||||||
|
elif svgfile[-4:] == '.png':
|
||||||
|
svgfile = svgfile[:-4]+'.svg'
|
||||||
|
output_format = 'png'
|
||||||
|
|
||||||
|
elif svgfile[-4:] == '.pdf':
|
||||||
|
svgfile = svgfile[:-4]+'.svg'
|
||||||
|
output_format = 'pdf'
|
||||||
|
else:
|
||||||
|
svgfile += '.svg'
|
||||||
|
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
|
||||||
|
if output_format == 'svg':
|
||||||
|
return 0
|
||||||
|
elif output_format == 'png':
|
||||||
|
svg2png(url=svgfile, write_to=svgfile[:-4]+'.png', dpi=600)
|
||||||
|
return 0
|
||||||
|
elif output_format == 'pdf':
|
||||||
|
svg2pdf(url=svgfile, write_to=svgfile[:-4]+'.pdf')
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
print(f"ERROR: Unbekanntes Output_format: {output_format}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
sys.exit(main(sys.argv))
|
25
qrr.py
25
qrr.py
|
@ -1,13 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import qrcode
|
from qrcode import make as qrcode_make
|
||||||
import qrcode.image.svg
|
import qrcode.image.svg
|
||||||
from svgutils import transform as st
|
from svgutils import transform as st
|
||||||
from ch_kreuz import swisscross as get_swisscross
|
from ch_kreuz import swisscross as get_swisscross
|
||||||
from ch_kreuz import white as get_white
|
from ch_kreuz import white as get_white
|
||||||
from svgutils.compose import Figure
|
from svgutils.compose import Figure
|
||||||
from cairosvg import (svg2pdf, svg2png)
|
from chardet import detect
|
||||||
|
|
||||||
|
|
||||||
class qr_rechnung():
|
class qr_rechnung():
|
||||||
|
@ -20,10 +20,13 @@ class qr_rechnung():
|
||||||
|
|
||||||
def set_data(self, data):
|
def set_data(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
self.data = data.encode('latin-1')
|
||||||
|
|
||||||
def set_data_from_textfile(self, textfile):
|
def set_data_from_textfile(self, textfile):
|
||||||
with open(textfile, 'r') as f:
|
with open(textfile, 'rb') as rawdata:
|
||||||
self.data = f.read()
|
charenc = detect(rawdata.read())['encoding']
|
||||||
|
with open(textfile, 'r', encoding=charenc) as f:
|
||||||
|
self.set_data(f.read())
|
||||||
|
|
||||||
def write_file(self, filepath, force=False):
|
def write_file(self, filepath, force=False):
|
||||||
global qrcode
|
global qrcode
|
||||||
|
@ -62,7 +65,6 @@ def help(args):
|
||||||
return '\n'.join([
|
return '\n'.join([
|
||||||
'{0}: Ungültige Eingabe',
|
'{0}: Ungültige Eingabe',
|
||||||
'Aufruf: {0} TEXTDATEI [SVG-ZIELDATEI]',
|
'Aufruf: {0} TEXTDATEI [SVG-ZIELDATEI]',
|
||||||
'Alternativ kann die ZIELDATEI auch mit .pdf oder .png enden.'
|
|
||||||
]).format(args[0])
|
]).format(args[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,13 +79,6 @@ def main(args):
|
||||||
svgfile = args[2]
|
svgfile = args[2]
|
||||||
if svgfile[-4:] == '.svg':
|
if svgfile[-4:] == '.svg':
|
||||||
pass
|
pass
|
||||||
elif svgfile[-4:] == '.png':
|
|
||||||
svgfile = svgfile[:-4]+'.svg'
|
|
||||||
output_format = 'png'
|
|
||||||
|
|
||||||
elif svgfile[-4:] == '.pdf':
|
|
||||||
svgfile = svgfile[:-4]+'.svg'
|
|
||||||
output_format = 'pdf'
|
|
||||||
else:
|
else:
|
||||||
svgfile += '.svg'
|
svgfile += '.svg'
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -101,12 +96,6 @@ def main(args):
|
||||||
return 1
|
return 1
|
||||||
if output_format == 'svg':
|
if output_format == 'svg':
|
||||||
return 0
|
return 0
|
||||||
elif output_format == 'png':
|
|
||||||
svg2png(url=svgfile, write_to=svgfile[:-4]+'.png', dpi=600)
|
|
||||||
return 0
|
|
||||||
elif output_format == 'pdf':
|
|
||||||
svg2pdf(url=svgfile, write_to=svgfile[:-4]+'.pdf')
|
|
||||||
return 0
|
|
||||||
else:
|
else:
|
||||||
print(f"ERROR: Unbekanntes Output_format: {output_format}")
|
print(f"ERROR: Unbekanntes Output_format: {output_format}")
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in a new issue