Skip to main content

Train ticket barcode to json decoding library, using zxing-cpp decoding in combination with record interpreter, to transform content into json structure

Project description

ticket_decoder

Optional arguments for instance creation of DecoderFacade.

  • uic_public_key_xml_file = "cert/UIC_PublicKeys.xml"
    Relative path to the XML file containing UIC public keys you can obtain here: https://railpublickey.uic.org/ .
  • vdv_certificate_ldif_file = "cert/VDV_Certificates.ldif"
    Relative path to the LDIF file containing VDV certificates to decrypt VDV barcode content.
  • fail_on_decoder_error = false
    Fail when the aztec/barcode decoder gets an error if true or deliver an empty result when false.
  • fail_on_interpreter_error = false
    Fail when the interpretation of the data gets an error if true or deliver an empty result when false.

Provided python API is in an early state and the class DecoderFacade supports 3 methods right now only.

  • decode_bytes('...')

  • decode_base64('...') is considered for the use case you decode the raw data from aztec-code in advance via zxing-cpp or other aztec-code-decoding library of your choice and you want to decode raw train ticket barcode data to json only. In this case, be careful with the output of the decoder to avoid string encodings like UTF8 or other multi-byte encodings. Ideally try to get access to the raw byte array and just encode those bytes to base64 before passing it to the method. If your aztec-code-decoder provides a string-type only and you are able to pass a character-encoding option, try using 'ISO 8859-1' and cast the result string to raw bytes.

  • decode_files('...') detects and decodes aztec-codes from file or directories (PDF, image) and decodes barcode data to json. This is using zxing-cpp and opencv internally. It returns a dict (origin/input-path and json-string) of size x, while x is the amount of aztec-codes found on input. An image can contain always multiple barcodes, the return value is alway a mapping of origin to json content.

    • rotation_degree - Rotate image before processing for the given amount of degrees (default 0)
    • scale_percent - Scale image before processing in percent (default 100)
    • splitting_mode - Split image, 1st number specifies the no of parts to split, 2nd is the part used for processing, clockwise from top/left (default 11)
    • flipping_mode - Flip image around X if 1, around Y if 2, and around X and Y if 3 (default 0)

Example decoding directly from PDF or image

from ticket_decoder import DecoderFacade

decoder_facade = DecoderFacade()
print(decoder_facade.decode_files('path/2/your/ticket.pdf'))

Example decoding Aztec-Code in advance using zxingcpp and opencv on Python side

from ticket_decoder import DecoderFacade
from zxingcpp import read_barcodes
from cv2 import imread

image = imread('path/2/your/ticket.jpg')
if image is None:
    print("Image not found")
    exit(1)

barcodes = read_barcodes(image)
if barcodes is None:
    print("No barcodes found")
    exit(1)

decoder_facade = DecoderFacade(\
    uic_public_key_xml_file = "cert/UIC_PublicKeys.xml",\
    vdv_certificate_ldif_file = "cert/VDV_Certificates.ldif")

print(decoder_facade.decode_bytes(barcodes[0].bytes))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ticket_decoder-0.19.3.tar.gz (1.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_aarch64.whl (9.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

ticket_decoder-0.19.3-cp314-cp314-macosx_11_0_arm64.whl (7.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_aarch64.whl (9.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

ticket_decoder-0.19.3-cp313-cp313-macosx_11_0_arm64.whl (7.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file ticket_decoder-0.19.3.tar.gz.

File metadata

  • Download URL: ticket_decoder-0.19.3.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ticket_decoder-0.19.3.tar.gz
Algorithm Hash digest
SHA256 90ce093793af76e7882bcd44958fdc2e3bea6b851746b5956f623ca1235e2826
MD5 4734e8c49f1aed91f27aa60b76a596ec
BLAKE2b-256 200f9826dc43bb4c8a9226816dee488c35f5b39299d9a00f771036b5521c6786

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.3.tar.gz:

Publisher: pypi.yml on user4223/ticket-decoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4d5e2b813498fd0e61d31fd8198f3e7a0957339a6f52934253f101749bc1ea1c
MD5 e1ae1ed5ae8be106d81123c1d44a140b
BLAKE2b-256 725b8e9f5fb07551a7c6d71da68ee3bd726d392eed1a8089c826a373abab8444

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_x86_64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 e98e347b53646a5df4f325035372285b57c70b04b3cac9e0188a1042484cc6bf
MD5 9207f14fdb5aedbacc667b3f6e52d812
BLAKE2b-256 bf0c77f182ff087fa680081e14748aedbc5a1f325a12df42a161f0b056512dfa

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.3-cp314-cp314-manylinux_2_34_aarch64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticket_decoder-0.19.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2891c08fd9c3d7f0bc74dd74238c68e6126730a36b576b23052cc92a9402f342
MD5 53c293185a9b382b0dd7400ec95b7df9
BLAKE2b-256 c2418d897cd39b7f4f3dcbaae50f3d9f510689786366ad24d187f3c447897e49

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.3-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d2364153df9bc887e7776b01a68b254522c9f241414b4ebfb9d91999a6c534c6
MD5 1bf66445e549612aa0df0e38e2993239
BLAKE2b-256 4d929fa9308aac25b9878acd6c483b68b2d155844f33d4e7042f39a95016ec59

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ef72234dad8bb9f208aba2af893ff4c7765da31d0b3ccdd4aea1ae63289df71f
MD5 abb46c311a9eef453ff1c53651176f4e
BLAKE2b-256 c858641d001cc475a2b1bbe35836f9fb9f3bd643781829378ce8b1a0d1baff8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.3-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticket_decoder-0.19.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fea27002594dc62ec6b06048a20c18be6dc00a99d711b07e2e9f2622ec25f5d2
MD5 13d6ab30ab9751338f11c6808da95bca
BLAKE2b-256 2784e77f31e446eeaa0c9696258ff661e0495d6a472c2334822b849dede7a413

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.3-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page