summary refs log tree commit diff
path: root/.config/timewarrior/extensions/waybar
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-x.config/timewarrior/extensions/waybar52
1 files changed, 52 insertions, 0 deletions
diff --git a/.config/timewarrior/extensions/waybar b/.config/timewarrior/extensions/waybar
new file mode 100755
index 0000000..45e3f03
--- /dev/null
+++ b/.config/timewarrior/extensions/waybar
@@ -0,0 +1,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()