forked from kfdm-archive/thehitlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thl.py
executable file
·62 lines (46 loc) · 1.44 KB
/
thl.py
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
#!/usr/bin/env python
import sys
from optparse import OptionParser
from clint.textui import puts, colored
import TheHitList
USAGE = '''usage: %prog [options] <command>
commands
list List tasks
add <string> Add new task
'''
class THLParser(OptionParser):
def __init__(self):
OptionParser.__init__(self, usage=USAGE)
self.add_option("--list", dest="list",
default='inbox', help="Use a specific list")
def parse_args(self):
opts, args = OptionParser.parse_args(self)
if len(args) == 0:
args = ['list']
command = args.pop(0).lower()
if command not in ['add', 'list']:
parser.error('Invalid command')
return command, opts, args
def show_tasks(thl, opts, args):
if len(args) == 0:
list = 'today'
else:
list = args.pop(0)
puts(colored.yellow('Showing tasks in %s' % list))
for task in thl.find_list(list).tasks():
print (task.title)
def add_task(thl, opts, args):
puts(colored.yellow('Adding task to %s' % opts.list))
list = thl.find_list(opts.list)
task = TheHitList.Task()
task.title = ' '.join(args)
list.add_task(task)
def main():
command, opts, args = THLParser().parse_args()
thl = TheHitList.Application()
if command == 'list':
show_tasks(thl, opts, args)
if command == 'add':
add_task(thl, opts, args)
if __name__ == '__main__':
main()