#!/usr/bin/env python # Look for decimal numbers in text that could plausibly be Unix timestamps, and # expand them into human-readable form. # Adam Sampson import sys, re, time num_re = re.compile(r'\b(\d+)\b') def replace(m): n = int(m.group(1)) if n >= 200000000 and n < (1 << 32): return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(n)) else: return m.group(1) def expand(f): while True: l = f.readline() if l == "": break sys.stdout.write(num_re.sub(replace, l)) # FIXME: This should be pulled out into a "filter" module if __name__ == "__main__": if len(sys.argv) == 1: expand(sys.stdin) else: for fn in sys.argv[1:]: f = open(fn) expand(f) f.close()