From 907b7e7659a0f7ff7e9ec2a3422474e3b0967b90 Mon Sep 17 00:00:00 2001 From: Simon Rieger Date: Wed, 28 Jun 2023 08:43:28 +0200 Subject: [PATCH] add new waybar-khal script --- .../waybar/executable_waybar-khal-old.py | 18 +++++++++++++ dot_config/waybar/executable_waybar-khal.py | 27 +++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 dot_config/waybar/executable_waybar-khal-old.py diff --git a/dot_config/waybar/executable_waybar-khal-old.py b/dot_config/waybar/executable_waybar-khal-old.py new file mode 100644 index 0000000..33c6679 --- /dev/null +++ b/dot_config/waybar/executable_waybar-khal-old.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +import json +import subprocess +data = {} +output = subprocess.check_output("khal list now 7days --format \"{start-end-time-style} {title}\"", shell=True).decode("utf-8") +lines = output.split("\n") +new_lines = [] +for line in lines: + if len(line) and line[0].isalpha(): + line = "\n"+line+"" + new_lines.append(line) +output = "\n".join(new_lines).strip() +if "Today" in output: + data['text'] = " " + output.split('\n')[1] +else: + data['text'] = "" +data['tooltip'] = output +print(json.dumps(data)) diff --git a/dot_config/waybar/executable_waybar-khal.py b/dot_config/waybar/executable_waybar-khal.py index 33c6679..492138c 100644 --- a/dot_config/waybar/executable_waybar-khal.py +++ b/dot_config/waybar/executable_waybar-khal.py @@ -1,18 +1,35 @@ #!/usr/bin/env python -import json + import subprocess +import datetime +import json +from html import escape + data = {} + +today = datetime.date.today().strftime("%Y-%m-%d") + +next_week = (datetime.date.today() + + datetime.timedelta(days=10)).strftime("%Y-%m-%d") + +#output = subprocess.check_output("khal list now "+next_week, shell=True) output = subprocess.check_output("khal list now 7days --format \"{start-end-time-style} {title}\"", shell=True).decode("utf-8") +#output = output.decode("utf-8") + lines = output.split("\n") new_lines = [] for line in lines: - if len(line) and line[0].isalpha(): - line = "\n"+line+"" - new_lines.append(line) + clean_line = escape(line).split(" ::")[0] + if len(clean_line) and not clean_line[0] in ['0', '1', '2']: + clean_line = "\n"+clean_line+"" + new_lines.append(clean_line) output = "\n".join(new_lines).strip() -if "Today" in output: + +if today in output: data['text'] = " " + output.split('\n')[1] else: data['text'] = "" + data['tooltip'] = output + print(json.dumps(data))