change khal

This commit is contained in:
Simon Rieger 2023-07-02 03:08:41 +02:00
parent cb2921f4a4
commit ccd67e27c1
2 changed files with 27 additions and 27 deletions

View file

@ -1,18 +1,35 @@
#!/usr/bin/env python #!/usr/bin/env python
import json
import subprocess import subprocess
import datetime
import json
from html import escape
data = {} 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 = 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") lines = output.split("\n")
new_lines = [] new_lines = []
for line in lines: for line in lines:
if len(line) and line[0].isalpha(): clean_line = escape(line).split(" ::")[0]
line = "\n<b>"+line+"</b>" if len(clean_line) and not clean_line[0] in ['0', '1', '2']:
new_lines.append(line) clean_line = "\n<b>"+clean_line+"</b>"
new_lines.append(clean_line)
output = "\n".join(new_lines).strip() output = "\n".join(new_lines).strip()
if "Today" in output:
if today in output:
data['text'] = "" + output.split('\n')[1] data['text'] = "" + output.split('\n')[1]
else: else:
data['text'] = "" data['text'] = ""
data['tooltip'] = output data['tooltip'] = output
print(json.dumps(data)) print(json.dumps(data))

View file

@ -1,35 +1,18 @@
#!/usr/bin/env python #!/usr/bin/env python
import subprocess
import datetime
import json import json
from html import escape import subprocess
data = {} 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 = 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") lines = output.split("\n")
new_lines = [] new_lines = []
for line in lines: for line in lines:
clean_line = escape(line).split(" ::")[0] if len(line) and line[0].isalpha():
if len(clean_line) and not clean_line[0] in ['0', '1', '2']: line = "\n<b>"+line+"</b>"
clean_line = "\n<b>"+clean_line+"</b>" new_lines.append(line)
new_lines.append(clean_line)
output = "\n".join(new_lines).strip() output = "\n".join(new_lines).strip()
if "Today" in output:
if today in output:
data['text'] = "" + output.split('\n')[1] data['text'] = "" + output.split('\n')[1]
else: else:
data['text'] = "" data['text'] = ""
data['tooltip'] = output data['tooltip'] = output
print(json.dumps(data)) print(json.dumps(data))