blob: 45e3f03d8257309c2f48357b87d8f8406022caf3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/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()
|