#!/usr/bin/env python import subprocess import datetime import json from html import escape data = {} today = datetime.date.today().strftime("%Y-%m-%d") days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today", "Tomorrow" ] next_week = (datetime.date.today() + datetime.timedelta(days=10)).strftime("%Y-%m-%d") output = subprocess.check_output("khal list --format \"{title}\" now "+next_week, shell=True) output = output.decode("utf-8") lines = output.split("\n") new_lines = [] for line in lines: clean_line = escape(line).split(" ::")[0] # bold headers if len(clean_line) and clean_line.split(",")[0] in days: clean_line = f"\n{clean_line}" new_lines.append(clean_line) output = "\n".join(new_lines).strip() today_text = datetime.date.today().strftime("%a, %d %b") if today in output: event = output.split('\n')[1] data['text'] = f" {today_text}: {event}" else: data['text'] = f" {today_text}" data['tooltip'] = output print(json.dumps(data))