waybar: add start/end times to calendar, general improvements
This commit is contained in:
		
							parent
							
								
									3ddba3831d
								
							
						
					
					
						commit
						b6180db9f6
					
				
					 2 changed files with 38 additions and 20 deletions
				
			
		| 
						 | 
					@ -12,26 +12,40 @@ days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Su
 | 
				
			||||||
 | 
					
 | 
				
			||||||
next_week = (datetime.date.today() + datetime.timedelta(days=10)).strftime("%Y-%m-%d")
 | 
					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)
 | 
					title = subprocess.check_output("khal list --format \"{title}\" now "+next_week,
 | 
				
			||||||
output = output.decode("utf-8")
 | 
					        shell=True).decode("UTF-8").split("\n")
 | 
				
			||||||
 | 
					start = subprocess.check_output("khal list --format \"{start}\" now "+next_week,
 | 
				
			||||||
 | 
					        shell=True).decode("UTF-8").split("\n")
 | 
				
			||||||
 | 
					end = subprocess.check_output("khal list --format \"{end}\" now "+next_week,
 | 
				
			||||||
 | 
					        shell=True).decode("UTF-8").split("\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
lines = output.split("\n")
 | 
					lines = ""
 | 
				
			||||||
new_lines = []
 | 
					for i in range(len(title)):
 | 
				
			||||||
for line in lines:
 | 
					    t = escape(title[i])
 | 
				
			||||||
    clean_line = escape(line).split(" ::")[0]
 | 
					    s = escape(start[i])
 | 
				
			||||||
    # bold headers
 | 
					    e = escape(end[i])
 | 
				
			||||||
    if len(clean_line) and clean_line.split(",")[0] in days:
 | 
					    line = ""
 | 
				
			||||||
        clean_line = f"\n<b>{clean_line}</b>"
 | 
					    if len(t) and t.split(",")[0] in days:
 | 
				
			||||||
    new_lines.append(clean_line)
 | 
					        line = f"\n<b>{t}</b>"
 | 
				
			||||||
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:
 | 
					    else:
 | 
				
			||||||
    data['text'] = f" {today_text}"
 | 
					        ss = s.split(" ")
 | 
				
			||||||
 | 
					        es = e.split(" ")
 | 
				
			||||||
 | 
					        if len(es) == 1 or len(ss) == 1:
 | 
				
			||||||
 | 
					            line = f"<i>{t}</i>"
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            line = f"{ss[1]} - {es[1]}: {t}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
data['tooltip'] = output
 | 
					    lines += f"{line}\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if today in lines:
 | 
				
			||||||
 | 
					    event = lines.split('\n')[2]
 | 
				
			||||||
 | 
					    if len(event) > 30:
 | 
				
			||||||
 | 
					        event = f"{event[0:30]}…"
 | 
				
			||||||
 | 
					    data["text"] = f"{event}"
 | 
				
			||||||
 | 
					    data["alt"] = "event"
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    data["text"] = "-"
 | 
				
			||||||
 | 
					    data["alt"] = "idle"
 | 
				
			||||||
 | 
					data["tooltip"] = lines
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print(json.dumps(data))
 | 
					print(json.dumps(data))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,11 +41,15 @@
 | 
				
			||||||
    "format": " <span foreground='#268bd2'>❮</span> "
 | 
					    "format": " <span foreground='#268bd2'>❮</span> "
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "custom/calendar": {
 | 
					  "custom/calendar": {
 | 
				
			||||||
    "format": "{}",
 | 
					    "format": "{icon} {}",
 | 
				
			||||||
    "tooltip-format": "{}",
 | 
					    "tooltip-format": "{}",
 | 
				
			||||||
    "tooltip": true,
 | 
					    "tooltip": true,
 | 
				
			||||||
    "return-type": "json",
 | 
					    "return-type": "json",
 | 
				
			||||||
    "interval": 300,
 | 
					    "interval": 300,
 | 
				
			||||||
 | 
					    "format-icons": {
 | 
				
			||||||
 | 
					      "event": "<span foreground='#b8bb26'></span> ",
 | 
				
			||||||
 | 
					      "idle": " "
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "escape": false,
 | 
					    "escape": false,
 | 
				
			||||||
    "exec": "$HOME/.config/sway/bin/waybar_khal.py 2> /dev/null",
 | 
					    "exec": "$HOME/.config/sway/bin/waybar_khal.py 2> /dev/null",
 | 
				
			||||||
    "on-click": "foot -T float khal interactive"
 | 
					    "on-click": "foot -T float khal interactive"
 | 
				
			||||||
| 
						 | 
					@ -79,7 +83,7 @@
 | 
				
			||||||
    "exec-if": "pgrep plexamp"
 | 
					    "exec-if": "pgrep plexamp"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "clock": {
 | 
					  "clock": {
 | 
				
			||||||
    "format": "<span foreground='#ebdbb2'> </span>{:%H:%M}",
 | 
					    "format": "<span foreground='#ebdbb2'> </span>{: %a, %b %d, %H:%M}",
 | 
				
			||||||
    "on-click": "foot -T float khal interactive"
 | 
					    "on-click": "foot -T float khal interactive"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "cpu": {
 | 
					  "cpu": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue