-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathon-modify-watson.py
More file actions
executable file
·78 lines (58 loc) · 2.1 KB
/
on-modify-watson.py
File metadata and controls
executable file
·78 lines (58 loc) · 2.1 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright © 2016 Yannick Loiseau <me@yloiseau.net>
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
"""
on-modify hook for taskwarrior.
This hook connect taskwarrior and watson.
When starting a task in taskwarrior, the hook starts a corresponding project in
watson. The project and keywords of the taskwarrior task are used in watson.
When stopping a task in taskwarrior, the hook stops the watson project.
To install, copy in ~/.task/hooks/on-modify-tw-watson.py and make executable.
https://taskwarrior.org/
https://github.com/TailorDev/Watson
"""
import sys
import json
from watson import Watson
def load_json():
return (json.loads(sys.stdin.readline()), json.loads(sys.stdin.readline()))
def is_starting(old, new):
return "start" in new and "start" not in old
def is_stopping(old, new):
return "start" in old and "start" not in new
def stop_watson():
watson = Watson()
if watson.is_started:
watson.stop()
watson.save()
def start_watson(task):
watson = Watson()
if watson.is_started and watson.config.getboolean('options', 'stop_on_start'):
watson.stop()
watson.start(
"@".join([
task.get("description", "").strip(),
task.get("project", "None").strip()]),
[t.strip() for t in task.get("tags") or [] if t.strip() != '' ])
watson.save()
def main(args):
try:
old, new = load_json()
print(json.dumps(new))
if is_stopping(old, new):
stop_watson()
print("Watson project {} {} stopped".format(
new.get("project"), new.get("tags")))
elif is_starting(old, new):
start_watson(new)
print("Watson project {} {} started".format(
new.get("project"), new.get("tags")))
return 0
except Exception as e:
print(str(e))
return 1
if __name__ == "__main__":
sys.exit(main(sys.argv))