Created
March 31, 2020 12:51
-
-
Save Frank-Buss/b59e2abff0e28c1ec933774391c88312 to your computer and use it in GitHub Desktop.
Australia Post tracking number extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Converts the 56 digits 2D Australia Post barcode to the 22 digits tracking number. | |
# Reads from stdin until newline, and copies the tracking number to the clipboard. | |
# Other characters then digits are removed. | |
# | |
# Needs Python3 and the clipboard library. Install from the command line like this: | |
# pip3 install clipboard | |
# Then save this file as barcode.py and start the script like this: | |
# python barcode.py | |
# | |
# test input: | |
# 01990000000000000003070045678901234567898000000000000000 | |
# output: | |
# tracking code 0307004567890123456789 copied to clipboard | |
# | |
# tested in Windows and Linux | |
import clipboard | |
import sys | |
for line in sys.stdin: | |
digits = "".join(filter(str.isdigit, line)) | |
if len(digits) == 56: | |
tracking = digits[18:40] | |
clipboard.copy(tracking) | |
print("tracking code " + tracking + " copied to clipboard") | |
else: | |
print("wrong length: %d" % (len(digits))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment