Passed
Push — master ( e9b793...4693c5 )
by Alexander
01:00
created

things3_cli.Things3CLI.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
"""Simple read-only Thing 3 CLI."""
5
6
from __future__ import print_function
7
8
__author__ = "Alexander Willner"
9
__copyright__ = "2020 Alexander Willner"
10
__credits__ = ["Alexander Willner"]
11
__license__ = "Apache"
12
__version__ = "0.0.1"
13
__maintainer__ = "Alexander Willner"
14
__email__ = "[email protected]"
15
__status__ = "Development"
16
17
import argparse
18
import json
19
import things3
20
21
22
class Things3CLI():
23
    """Simple read-only Thing 3 CLI."""
24
25
    I_UUID = 0
26
    I_TITLE = 1
27
    I_CONTEXT = 2
28
    I_CONTEXT_UUID = 3
29
    print_json = False
30
31
    def __init__(self, print_json):
32
        self.print_json = print_json
33
34
    def print_tasks(self, tasks):
35
        """Print a task."""
36
        for task in tasks:
37
            title = task[self.I_TITLE]
38
            context = str(task[self.I_CONTEXT])
39
            if self.print_json:
40
                print(json.dumps([{
41
                    'title': title,
42
                    'context': context
43
                    }]))
44
            else:
45
                print(' - ' + title + ' (' + context + ')')
46
47
    def print_today(self):
48
        """Show Today."""
49
        self.print_tasks(things3.get_today())
50
51
    def print_inbox(self):
52
        """Show Inbox."""
53
        self.print_tasks(things3.get_inbox())
54
55
    @classmethod
56
    def print_unimplemented(cls):
57
        """Show warning that method is not yet implemented."""
58
        print("not implemented yet")
59
60
61
def main(args):
62
    """ Main entry point of the app """
63
    things = Things3CLI(args.json)
64
    if args.command == "inbox":
65
        things.print_inbox()
66
    elif args.command == "today":
67
        things.print_today()
68
    else:
69
        Things3CLI.print_unimplemented()
70
71
72
if __name__ == "__main__":
73
    PARSER = argparse.ArgumentParser(
74
        description='Simple read-only Thing 3 CLI.')
75
76
    SUBPARSERS = PARSER.add_subparsers(help='One of the following commands:',
77
                                       metavar="command",
78
                                       required=True,
79
                                       dest="command")
80
    SUBPARSERS.add_parser('inbox',
81
                          help='Shows all inbox tasks')
82
    SUBPARSERS.add_parser('today',
83
                          help='Shows all todays tasks')
84
    SUBPARSERS.add_parser('upcoming',
85
                          help='Shows all upcoming tasks')
86
    SUBPARSERS.add_parser('next',
87
                          help='Shows all next tasks')
88
    SUBPARSERS.add_parser('someday',
89
                          help='Shows all someday tasks')
90
    SUBPARSERS.add_parser('completed',
91
                          help='Shows all completed tasks')
92
    SUBPARSERS.add_parser('cancelled',
93
                          help='Shows all cancelled tasks')
94
    SUBPARSERS.add_parser('trashed',
95
                          help='Shows all trashed tasks')
96
    SUBPARSERS.add_parser('feedback',
97
                          help='Give feedback')
98
    SUBPARSERS.add_parser('all',
99
                          help='Shows all tasks')
100
    SUBPARSERS.add_parser('csv',
101
                          help='Exports all tasks as CSV')
102
    SUBPARSERS.add_parser('due',
103
                          help='Shows all tasks with due dates')
104
    SUBPARSERS.add_parser('headings',
105
                          help='Shows all headings')
106
    SUBPARSERS.add_parser('hours',
107
                          help='Shows how many hours have been planned today')
108
    SUBPARSERS.add_parser('ical',
109
                          help='Shows all tasks ordered by due date as iCal')
110
    SUBPARSERS.add_parser('logbook',
111
                          help='Shows all tasks completed today')
112
    SUBPARSERS.add_parser('mostClosed',
113
                          help='Shows days on which most tasks were closed')
114
    SUBPARSERS.add_parser('mostCancelled',
115
                          help='Shows days on which most tasks were cancelled')
116
    SUBPARSERS.add_parser('mostTrashed',
117
                          help='Shows days on which most tasks were trashed')
118
    SUBPARSERS.add_parser('mostCreated',
119
                          help='Shows days on which most tasks were created')
120
    SUBPARSERS.add_parser('mostTasks',
121
                          help='Shows projects that have most tasks')
122
    SUBPARSERS.add_parser('mostCharacters',
123
                          help='Shows tasks that have most characters')
124
    SUBPARSERS.add_parser('nextish',
125
                          help='Shows all nextish tasks')
126
    SUBPARSERS.add_parser('old',
127
                          help='Shows all old tasks')
128
    SUBPARSERS.add_parser('projects',
129
                          help='Shows all projects')
130
    SUBPARSERS.add_parser('repeating',
131
                          help='Shows all repeating tasks')
132
    SUBPARSERS.add_parser('schedule',
133
                          help='Schedules an event using a template')
134
    SUBPARSERS.add_parser('search',
135
                          help='Searches for a specific task')
136
    SUBPARSERS.add_parser('stat',
137
                          help='Provides a number of statistics')
138
    SUBPARSERS.add_parser('statcsv',
139
                          help='Exports some statistics as CSV')
140
    SUBPARSERS.add_parser('subtasks',
141
                          help='Shows all subtasks')
142
    SUBPARSERS.add_parser('tag',
143
                          help='Shows all tasks with the waiting for tag')
144
    SUBPARSERS.add_parser('tags',
145
                          help='Shows all tags ordered by their usage')
146
    SUBPARSERS.add_parser('waiting',
147
                          help='Shows all tasks with the waiting for tag')
148
149
    PARSER.add_argument("-j", "--json",
150
                        action="store_true", default=False,
151
                        help="output as JSON", dest="json")
152
    PARSER.add_argument(
153
        "--version",
154
        action="version",
155
        version="%(prog)s (version {version})".format(version=__version__))
156
157
    ARGUMENTS = PARSER.parse_args()
158
    main(ARGUMENTS)
159