summaryrefslogtreecommitdiffstats
path: root/py3status/modules/taskwarrior.py
blob: 65407e5b0757a0b30fce81ff5e109462b90e9f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
Display currently active (started) taskwarrior tasks.

Configuration parameters:
    - cache_timeout : how often we refresh this module in seconds (5s default)

Requires
    - task

@author James Smith http://jazmit.github.io/
@license BSD
"""

# import your useful libs here
from time import time
from subprocess import check_output
import json
import shlex


class Py3status:
    """
    """
    # available configuration parameters
    cache_timeout = 5

    def taskWarrior(self, i3s_output_list, i3s_config):
        command = 'task start.before:tomorrow status:pending export'
        taskwarrior_output = check_output(shlex.split(command))
        tasks_json = json.loads('[' + taskwarrior_output.decode('utf-8') + ']')

        def describeTask(taskObj):
            return str(taskObj['id']) + ' ' + taskObj['description']

        result = ', '.join(map(describeTask, tasks_json))
        response = {
            'cached_until': time() + self.cache_timeout,
            'full_text': result
        }
        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)