#!/usr/bin/env python3 """Stamp each JSONL line read from stdin with the wall-clock time it arrived (t_unix_ms). Test tooling.""" import json import sys import time for line in sys.stdin: line = line.rstrip("\n") t = int(time.time() * 1000) try: d = json.loads(line) if isinstance(d, dict): d["t_unix_ms"] = t line = json.dumps(d, separators=(",", ":")) else: line = json.dumps({"t_unix_ms": t, "value": d}) except ValueError: line = json.dumps({"t_unix_ms": t, "raw": line}) sys.stdout.write(line + "\n") sys.stdout.flush()