From f69e9954fafeaf5983dff8c2aae4b286d12a8418 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 15 Jul 2015 23:06:21 +0100 Subject: Added TaskWarrior module --- py3status/modules/taskwarrior.py | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 py3status/modules/taskwarrior.py diff --git a/py3status/modules/taskwarrior.py b/py3status/modules/taskwarrior.py new file mode 100644 index 0000000..a464a32 --- /dev/null +++ b/py3status/modules/taskwarrior.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +""" +Display currently active (started) taskwarrior tasks. + +Configuration parameters: + - cache_timeout : how often we refresh this module in seconds + +Requires + - jq + - awk + +@author James Smith http://jazmit.github.io/ +@license BSD +""" + +# import your useful libs here +from time import time +import subprocess + +class Py3status: + cache_timeout = 5 + + def taskWarrior(self, i3s_output_list, i3s_config): + active_task = subprocess.check_output( + """task start.before:tomorrow status:pending export \ + | awk 'BEGIN { print "["} { print $0 } END { print "]"}' \ + | jq -r 'map( (.id | tostring) + " " + .description ) | join(", ")' \ + """, + shell=True).strip() + response = { + 'cached_until': time() + self.cache_timeout, + 'full_text': active_task + } + return response + +if __name__ == "__main__": + """ + Test this module by calling it directly. + """ + from time import sleep + x = Py3status() + config = { + 'color_bad': '#FF0000', + 'color_degraded': '#FFFF00', + 'color_good': '#00FF00' + } + while True: + print(x.taskWarrior([], config)) + sleep(1) -- cgit v1.3 From 8e6dac5a7135476c8f9865340559af9047dc2246 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 16 Jul 2015 18:46:19 +0100 Subject: Edited taskwarrior module to conform to best practices --- py3status/modules/taskwarrior.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/py3status/modules/taskwarrior.py b/py3status/modules/taskwarrior.py index a464a32..75faa8f 100644 --- a/py3status/modules/taskwarrior.py +++ b/py3status/modules/taskwarrior.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - """ Display currently active (started) taskwarrior tasks. @@ -7,8 +6,7 @@ Configuration parameters: - cache_timeout : how often we refresh this module in seconds Requires - - jq - - awk + - task @author James Smith http://jazmit.github.io/ @license BSD @@ -16,24 +14,30 @@ Requires # import your useful libs here from time import time -import subprocess +from subprocess import check_output +import shlex +import json + class Py3status: cache_timeout = 5 def taskWarrior(self, i3s_output_list, i3s_config): - active_task = subprocess.check_output( - """task start.before:tomorrow status:pending export \ - | awk 'BEGIN { print "["} { print $0 } END { print "]"}' \ - | jq -r 'map( (.id | tostring) + " " + .description ) | join(", ")' \ - """, - shell=True).strip() + command = "task start.before:tomorrow status:pending export" + taskwarrior_output = check_output(shlex.split(command)) + tasks_json = json.loads("[" + taskwarrior_output + "]") + + def describeTask(taskObj): + return str(taskObj['id']) + " " + taskObj['description'] + + result = ', '.join(map(describeTask, tasks_json)) response = { 'cached_until': time() + self.cache_timeout, - 'full_text': active_task + 'full_text': result } return response + if __name__ == "__main__": """ Test this module by calling it directly. -- cgit v1.3