Created
March 28, 2019 23:13
-
-
Save AlexanderBrevig/664c90f3132d38919d4d48132110b805 to your computer and use it in GitHub Desktop.
An updated module for bumblebee-status that uses todo.sh and lists tasks that are over due
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pylint: disable=C0111,R0903 | |
# place in bumblebee-status/bumblebee/modules/ | |
# https://github.com/tobi-wan-kenobi/bumblebee-status/blob/master/bumblebee/modules/todo.py | |
"""Displays the number of todo items from a text file | |
Parameters: | |
* todo.file: File to read TODOs from (defaults to ~/Documents/todo.txt) | |
""" | |
import bumblebee.input | |
import bumblebee.output | |
import bumblebee.engine | |
import os.path | |
import subprocess | |
from datetime import datetime | |
class Module(bumblebee.engine.Module): | |
def __init__(self, engine, config): | |
super(Module, self).__init__(engine, config, | |
bumblebee.output.Widget(full_text=self.output) | |
) | |
self._doc = os.path.expanduser(self.parameter("file", "~/Documents/todo.txt")) | |
self._todos = self.count_items() | |
self._dueCount = 1 | |
def output(self, widget): | |
self._todos = self.count_items() | |
self._dueCount = self.count_overdue() | |
if self._dueCount > 0: | |
return str(self._dueCount) + "/" + str(self._todos) | |
else: | |
return str(self._todos) | |
def state(self, widgets): | |
if self._todos == 0: | |
return "empty" | |
return "items" | |
def count_overdue(self): | |
try: | |
result = subprocess.run(['/usr/bin/todo.sh', 'ls', 'due:'], stdout=subprocess.PIPE) | |
parts = result.stdout.decode().split('\n') | |
words = [y for x in parts for y in x.split(' ') if "due:" in y] | |
duecount = [1 for x in words if datetime.fromisoformat(x.strip("due:")) <= datetime.now()] | |
return duecount[0] | |
except Exception: | |
return 0 | |
def count_items(self): | |
try: | |
i = -1 | |
with open(self._doc) as f: | |
for i, l in enumerate(f): | |
pass | |
return i+1 | |
except Exception: | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment