Last active
January 6, 2021 02:35
-
-
Save chriscz/55ca9bf3aef18c5bc1ab3d54e0923607 to your computer and use it in GitHub Desktop.
A python script to notify you of your current TimeWarrior task
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
#!/usr/bin/env python | |
# Notifies the user of the curently active TimeWarrior task every m minutes (default 10min). | |
# Requirements | |
# - python 2.7 | |
# - pynotify | |
# Usage: | |
# python timewn.py [optional seconds] | |
import sys | |
import pynotify | |
from subprocess import check_output, CalledProcessError | |
from time import sleep | |
pynotify.init("markup") | |
def readtask(): | |
try: | |
lines = check_output(["timew"]).split('\n') | |
except CalledProcessError: | |
return None | |
lines = [_.strip() for _ in lines] | |
name = lines[0][len('Tracking'):].strip() | |
time = lines[3].split()[1] | |
return name, time | |
# check if anything is active | |
def start(seconds=10*60): | |
while True: | |
task = readtask() | |
msg = '<h3><font color="red"> No task in progress</font></h3>' | |
if task: | |
msg = """<h3><b> | |
Working on | |
<font color="red">{}</font> ({})</b></h3> | |
""".format(*task) | |
n = pynotify.Notification("<h2>TimeWarrior</h2>", msg) | |
n.show() | |
sleep(seconds) | |
if __name__ == '__main__': | |
# read time in seconds from arguments, or use 10 minutes as default | |
time = float(sys.argv[1]) if len(sys.argv) >= 2 else 10*60 | |
start(time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment