#!/bin/env python3 import fileinput, json from datetime import datetime, timezone, timedelta ICO="󰔚" CLS="timew" ALT="timew" def main() -> None: # only read actual json input = [] for line in fileinput.input(encoding='utf-8'): if len(input) != 0: input.append(line) if line == "[\n": input = [line] pass # parse json input = json.loads("".join(input)) # filter for active trackers input = list(filter(lambda x: not "end" in x, list(input))) # exit early if no tracker is running if len(input) == 0: output = {} else: # pick first input = input[0] # parse start startt = datetime.fromisoformat(input['start']) # get now nowt = datetime.now(timezone.utc); # round away microseconds nowt = nowt.replace(microsecond=0) # calc diff diff = nowt - startt.astimezone(timezone.utc) # make output output = { 'text': f"{ICO} {diff} {",".join(input['tags'])}", 'class': CLS, 'alt': ALT, } print(json.dumps(output), end='') if __name__ == "__main__": main()