]> git.gir.st - greenpass.git/commitdiff
support passing raw HC1 data via cmdline master
authorGeorg Lukas <georg@op-co.de>
Fri, 2 Jul 2021 09:30:47 +0000 (11:30 +0200)
committerTobias Girstmair <tobi@isticktoit.net>
Fri, 2 Jul 2021 20:22:52 +0000 (22:22 +0200)
greenpass.py

index 135c8e17b0736f2ae5e9342775ccdfb25ccae575..f81d60d868f9587a897a7581c8b3c24df8484a78 100644 (file)
@@ -13,6 +13,7 @@ import zlib
 import flynn
 import base45
 import PyPDF2
+import os
 from PIL import Image
 from pyzbar import pyzbar
 from datetime import datetime
@@ -27,21 +28,27 @@ if len(sys.argv) < 2:
     except:
         print(f"Usage: {sys.argv[0]} COVID-19-*-*-*.pdf", file=sys.stderr)
         print(f"Usage: {sys.argv[0]} QR_CODE.png", file=sys.stderr)
+        print(f"Usage: {sys.argv[0]} 'HC1:.....'", file=sys.stderr)
         sys.exit(1)
 else:
-    infile = sys.argv[1]
+    if os.path.exists(sys.argv[1]):
+        infile = sys.argv[1]
+    else:
+        infile = None
+        qr_data_zlib_b45 = sys.argv[1]
 
-if open(infile, "rb").read(4) == b"%PDF":
-    # extract QR code from PDF using hard-coded index, size and bit depth.
-    # This will only work with the official Austrian green pass PDFs.
-    pdf=PyPDF2.PdfFileReader(open(infile, "rb"))
-    qr_img = pdf.getPage(0)['/Resources']['/XObject']['/Im3']
-    qr_pil = Image.frombytes("1", (400,400), qr_img.getData())
-else: # assume image
-    qr_pil = Image.open(infile)
+if infile:
+    if open(infile, "rb").read(4) == b"%PDF":
+        # extract QR code from PDF using hard-coded index, size and bit depth.
+        # This will only work with the official Austrian green pass PDFs.
+        pdf=PyPDF2.PdfFileReader(open(infile, "rb"))
+        qr_img = pdf.getPage(0)['/Resources']['/XObject']['/Im3']
+        qr_pil = Image.frombytes("1", (400,400), qr_img.getData())
+    else: # assume image
+        qr_pil = Image.open(infile)
 
-# decode QR code into raw bytes:
-qr_data_zlib_b45 = pyzbar.decode(qr_pil)[0].data
+    # decode QR code into raw bytes:
+    qr_data_zlib_b45 = pyzbar.decode(qr_pil)[0].data
 
 # strip header ('HC1:') and decompress data:
 qr_data_zlib = base45.b45decode(qr_data_zlib_b45[4:])
Imprint / Impressum