Create proof-of-concept Python script to decode a receipt QR code.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 31 May 2017 19:44:06 +0000 (21:44 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 31 May 2017 19:47:20 +0000 (21:47 +0200)
read_receipt_example.py [new file with mode: 0644]

diff --git a/read_receipt_example.py b/read_receipt_example.py
new file mode 100644 (file)
index 0000000..d70414d
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/python3
+import datetime
+import numpy as np
+import zbar # pip install zbar-py
+import PIL.Image
+
+def cashstr_to_cent(cashstr):
+    return int(cashstr.replace(',', ''))
+
+image_color = PIL.Image.open('examples/receipt01.jpg')
+image_bw = image_color.convert('L')  # monochrome
+pixels = np.array(image_bw)
+
+scanner = zbar.Scanner()
+scan_results = scanner.scan(pixels)
+for scan_result in scan_results:
+    # https://github.com/a-sit-plus/at-registrierkassen-mustercode/releases/download/1.2-DOK/2016-09-05-Detailfragen-RKSV-V1.2.pdf
+    data_split = [str(d, 'UTF-8') for d in scan_result.data.split(b'_')]  # split and decode UTF-8 to string
+    _, r1at, device_id, receipt_id, date_time, cash0, cash1, cash2, cash3, cash4, counter, cert_serial, sig_prev, sig = data_split
+    date_time = datetime.datetime.strptime(date_time, '%Y-%m-%dT%H:%M:%S')
+    cash_cent = [cashstr_to_cent(cash) for cash in (cash0, cash1, cash2, cash3, cash4)]
+    print('Receipt')
+    print('* Date: {}'.format(date_time))
+    print('* Device ID: {}'.format(device_id))
+    print('* Receipt ID: {}'.format(receipt_id))
+    for i, cent in enumerate(cash_cent):
+        print('* Amount #{}: {} cent'.format(i+1, cent))
+    print('* Total amount: {} cent'.format(sum(cash_cent)))
+