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

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

ticket_decoder-0.20.0-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.0-cp313-cp313-manylinux_2_34_aarch64.whl (9.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

ticket_decoder-0.20.0-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.0.tar.gz.

File metadata

  • Download URL: ticket_decoder-0.20.0.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.0.tar.gz
Algorithm Hash digest
SHA256 72d72f1af0157887c7bd021e85d565df959bfde69ee60f6ce41437ce3e42b354
MD5 b8a7562f257e14c9839537fd658d16d2
BLAKE2b-256 805a92fa08987f8e5af202c72be42dc9025cc315a313647d81018187e704b819

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ticket_decoder-0.20.0-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 481640779c9f66d8a1fe9e16031a5defb9cb8e3744e2f3bd426db1974c6e5b21
MD5 e700d47ee41fd09c7c3af938171b0dbe
BLAKE2b-256 221f8a2b5b38f5b1a64f319a9ae70dad5cae7eae191bd6e11a88c21518ea75df

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ticket_decoder-0.20.0-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1283a271b459eb1c1e8ea8d928779a4d2ebf249017c81f12cadbfd1e935aef61
MD5 917f53382a4f920bded4b8782c61a186
BLAKE2b-256 df94a1b3decb64783ac55655c2fcbf0743c4cb467da1943740cfca69e26a78be

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ticket_decoder-0.20.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e3b62766a7b50ba821598afababb5486c879184eb6a3c9f3a8b0dada0faad68
MD5 0f05a5b671090e644a931ca53e76f6b8
BLAKE2b-256 02b0f0be6037c4f2055550fd71041ab1ec9fa09efca313bff4dbf3761e55cb4f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ticket_decoder-0.20.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e981f7fcfc62bba1256d0bd9cb9a56f48c9314baf049720e496497af12410c77
MD5 a556d0e50bb514defe22501a3059188e
BLAKE2b-256 8155aa1aa91a5ca2e6a7442542ab632b4a98a3d8fc58016da706028b84cf4b1f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ticket_decoder-0.20.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 90ccb7ce96321d2ac5d6995112d523a3252fafe46cfb594e28785422b04bb798
MD5 330b322fa4c59f44fc7eadfdfd14f8da
BLAKE2b-256 644c384889bd928ceee3ccf72508eab86b6a45d78a2adfd8cd4954245cf49faf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ticket_decoder-0.20.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8aab7af2661b9656cac3637de9c2b1e47e446081c25c9a81cdee8b430f3d40bf
MD5 b820b1e059d82351f4a5136c420d1966
BLAKE2b-256 91c91f1112171f1ec18f1e482d75de3bfeedde41f3fe0de228d1bddab862764f

See more details on using hashes here.

Provenance

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