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.20.1.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.20.1-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.20.1-cp314-cp314-manylinux_2_34_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

ticket_decoder-0.20.1-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.20.1-cp313-cp313-manylinux_2_34_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

ticket_decoder-0.20.1-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.20.1.tar.gz.

File metadata

  • Download URL: ticket_decoder-0.20.1.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.20.1.tar.gz
Algorithm Hash digest
SHA256 3f309def1138790e1862c851522390e2c05c29d2555c4231f3d4cfc4ba98a388
MD5 0df6898b3c464582fb9f3426915580d2
BLAKE2b-256 998103392703dc15ce1cbd6f9762c68e0454ae5b3bae41a220cd6b25598b30d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.20.1.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.20.1-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.20.1-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6cdec00d688d4dacf916c2918f5ac653522b2611872b65780fd02572c9e85aff
MD5 36faa17f003e65c9d7ab78c15ffbf26e
BLAKE2b-256 10a300f4d85bf5de679cdd1664a5cae4f4ac082125a47ade4652fb5aa913951b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.20.1-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.20.1-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.20.1-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 aecd3a4a6c21567f9eedd39dabe1a92a6ec47b4c7547fe5d0ebdfcfd455d5b10
MD5 32f5924a61dad2f87225fcbea2551999
BLAKE2b-256 fc7c425c115ff66c0c0945c3c27e4edc07270ea7a4d0dd9ed4424d844cd65dd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.20.1-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.20.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.20.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1c299016cba928cf10fca3c6267c8f1e5cfae0e6cb138d9e3a2a24733c8109d
MD5 090c90f499195175bdce0f3f56a1e294
BLAKE2b-256 9dadebaa8be710dc7d60263d5df9e83311b2b72792109d291304b03932b523bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.20.1-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.20.1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.20.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 14c73a99de32b6b12a99ff1bf72ef6810ee557494d1c522b3cdade1df41e7c15
MD5 4f746e21f6abed43102157b0b149805d
BLAKE2b-256 4eaafab5e2e98bc07c15843e8bb53b3aea84856c3b9a873d707ca35fac763c87

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.20.1-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.20.1-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.20.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 acc76880985eb6c1f93102e4035145cd6536d806c9a09fe75a318584b5136e56
MD5 69264ebd96b345a201dc104c673cfdae
BLAKE2b-256 cf291e5f54b6a1ff24812fa7a25c8a7e8f208c2a3ac5bd11857f6ab3f7885c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.20.1-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.20.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.20.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 338c5dab33432f04014e0c5be23e452191c50d2fd04d3affa573be9a27a64c92
MD5 5e847373e1dfdeb6fac6e64e70faab97
BLAKE2b-256 95659c9d1dfe77458faf1bb9614dfd66afb45d0188d51a7c4c21bae8cb3bef16

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.20.1-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