db-pkpass

Convert Deutsche Bahn PDF tickets to PKPass
git clone https://git.ce9e.org/db-pkpass.git

commit
bb66b9015d5f46086151dc7a22d1eed5fb701b24
parent
4a425800b23a83653d6bf862999ccd59f9cf8f17
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-05-30 15:02
add --debug options for json dump

Diffstat

M db_pkpass.py 21 ++++++++++++---------

1 files changed, 12 insertions, 9 deletions


diff --git a/db_pkpass.py b/db_pkpass.py

@@ -216,18 +216,21 @@ def extract_content(pdf):
  216   216 if __name__ == '__main__':
  217   217     parser = argparse.ArgumentParser()
  218   218     parser.add_argument('path')
   -1   219     parser.add_argument('--debug', action='store_true')
  219   220     args = parser.parse_args()
  220   221 
  221   222     with open(args.path, 'rb') as fh:
  222   223         pdf = pymupdf.open(stream=fh.read())
  223   224     content = extract_content(pdf)
  224   225 
  225    -1     output_path = args.path.replace('.pdf', '.pkpass')
  226    -1     with open(output_path, 'wb') as fh:
  227    -1         fh.write(dump_pkpass({
  228    -1             'pass.json': json.dumps(content).encode('utf-8'),
  229    -1             'icon.png': ICON,
  230    -1             'logo.png': ICON,
  231    -1         }))
  232    -1 
  233    -1     print(f'written to {output_path}')
   -1   226     if args.debug:
   -1   227         print(json.dumps(content, indent=2))
   -1   228     else:
   -1   229         output_path = args.path.replace('.pdf', '.pkpass')
   -1   230         with open(output_path, 'wb') as fh:
   -1   231             fh.write(dump_pkpass({
   -1   232                 'pass.json': json.dumps(content).encode('utf-8'),
   -1   233                 'icon.png': ICON,
   -1   234                 'logo.png': ICON,
   -1   235             }))
   -1   236         print(f'written to {output_path}')