Skip to content

Instantly share code, notes, and snippets.

@jcjones
Created May 27, 2020 21:47
Show Gist options
  • Save jcjones/d3ef387e6131d03fc77a6c4989f7585f to your computer and use it in GitHub Desktop.
Save jcjones/d3ef387e6131d03fc77a6c4989f7585f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import argparse
import sys
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument("data")
args = parser.parse_args()
print(f"Processing {args.data}")
if len(args.data) % 3 != 0:
print("Should be a multiple of 3.")
sys.exit(1)
if len(args.data) != 39:
print(
f"Should be 39 characters long, excluding the escape slashes: {len(args.data)}"
)
sys.exit(1)
parts = [args.data[i : i + 3] for i in range(0, len(args.data), 3)]
data = [int(n, base=8).to_bytes(1, byteorder="little") for n in parts]
year = f"{int(data[0])}{int(data[1])}"
month = f"{int(data[2])}{int(data[3])}"
day = f"{int(data[4])}{int(data[5])}"
hour = f"{int(data[6])}{int(data[7])}"
minute = f"{int(data[8])}{int(data[9])}"
second = f"{int(data[10])}{int(data[11])}"
tz = f"{data[12].decode('utf-8')}"
print(f"20{year}/{month}/{day} {hour}:{minute}:{second} {tz}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment