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 = true
    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 internally. It returns an array of tuples (input-path and json-result) of size x, while x is the amount of aztec-codes found on input. An image can contain always multiple barcodes, the the return value is alway a mapping of origin to content.

Example decoding directly from PDF or image

from ticket_decoder import DecoderFacade

decoder_facade = DecoderFacade(fail_on_interpreter_error = False)
for result in decoder_facade.decode_files('path/2/your/ticket.pdf'):
   print(result[1])

Decoding Aztec-Code in advance using zxingcpp on Python side

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

image = imread('path/2/your/ticket.jpg')

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

decoder_facade = DecoderFacade(\
    fail_on_interpreter_error = False,\
    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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

ticket_decoder-0.18-cp314-cp314-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ticket_decoder-0.18-cp313-cp313-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for ticket_decoder-0.18-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9d34897503ee728c91c3b9d8890efdc528198b8f707403d9ee4e965678c9ccc
MD5 31c8a99e6b0a6daffbf5282da6e58a48
BLAKE2b-256 619262f98573528033e3fabc26ed0b33c6ef9596103bda5a6f69a5d88cb43412

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ticket_decoder-0.18-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1dce3bda616e10dcbce51571f2f5c397b5731e33fde791eb84ebadb73df6e3d7
MD5 4e0aeb20f7674fbd65b8982e09684a31
BLAKE2b-256 1076a98ca1b2b1b5813edc66cebaa59ecbad6fd50f3960710adf41702f288ad2

See more details on using hashes here.

Provenance

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