Passed
Push — master ( bfae54...a15ea9 )
by Alexander
01:04
created

things3_cli.Things3CLI.print_today()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 1
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 things3
19
20
21
class Things3CLI():
22
    """Simple read-only Thing 3 CLI."""
23
24
    @classmethod
25
    def print_tasks(cls, tasks):
26
        """Print a task."""
27
        for task in tasks:
28
            print(' - ' + task[1])
29
30
    def print_today(self):
31
        """Show Today."""
32
        self.print_tasks(things3.get_today())
33
34
    def print_inbox(self):
35
        """Show Inbox."""
36
        self.print_tasks(things3.get_inbox())
37
38
    @classmethod
39
    def print_unimplemented(cls):
40
        """Show warning that method is not yet implemented."""
41
        print("not implemented yet")
42
43
44
def main(args):
45
    """ Main entry point of the app """
46
    COMMANDS[args.command][1]()
47
48
49
if __name__ == "__main__":
50
    PARSER = argparse.ArgumentParser(
51
        formatter_class=argparse.RawTextHelpFormatter)
52
    COMMANDS = {
53
        'inbox': ['Shows all inbox tasks',
54
                  Things3CLI().print_inbox],
55
        'today': ['Shows all todays tasks ordered by index',
56
                  Things3CLI().print_today],
57
        'upcoming': ['Shows all upcoming tasks ordered by date',
58
                     Things3CLI().print_unimplemented],
59
        'next': ['Shows all next tasks',
60
                 Things3CLI().print_unimplemented],
61
        'someday': ['Shows all someday tasks',
62
                    Things3CLI().print_unimplemented],
63
        'completed': ['Shows all completed tasks',
64
                      Things3CLI().print_unimplemented],
65
        'cancelled': ['Shows all cancelled tasks ordered by cancel date',
66
                      Things3CLI().print_unimplemented],
67
        'trashed': ['Shows all trashed tasks',
68
                    Things3CLI().print_unimplemented],
69
        'feedback': ['Opens the feedback web page to propose changes',
70
                     Things3CLI().print_unimplemented],
71
        'all': ['Shows all tasks',
72
                Things3CLI().print_unimplemented],
73
        'csv': ['Exports all tasks as semicolon seperated values',
74
                Things3CLI().print_unimplemented],
75
        'due': ['Shows all tasks ordered by due date',
76
                Things3CLI().print_unimplemented],
77
        'headings': ['Shows all headings',
78
                     Things3CLI().print_unimplemented],
79
        'hours': ['Shows how many hours of work have been planned for today',
80
                  Things3CLI().print_unimplemented],
81
        'ical': ['Shows all tasks ordered by due date as iCal',
82
                 Things3CLI().print_unimplemented],
83
        'logbook': ['Shows all tasks completed today',
84
                    Things3CLI().print_unimplemented],
85
        'mostClosed': ['Shows all days on which most tasks were closed',
86
                       Things3CLI().print_unimplemented],
87
        'mostCancelled': ['Shows all days on which most tasks were cancelled',
88
                          Things3CLI().print_unimplemented],
89
        'mostTrashed': ['Shows all days on which most tasks were trashed',
90
                        Things3CLI().print_unimplemented],
91
        'mostCreated': ['Shows all days on which most tasks were created',
92
                        Things3CLI().print_unimplemented],
93
        'mostTasks': ['Shows all projects that have most tasks',
94
                      Things3CLI().print_unimplemented],
95
        'mostCharacters': ['Shows all tasks that have most characters',
96
                           Things3CLI().print_unimplemented],
97
        'nextish': ['Shows all nextish tasks',
98
                    Things3CLI().print_unimplemented],
99
        'old': ['Shows all old tasks',
100
                Things3CLI().print_unimplemented],
101
        'projects': ['Shows all projects',
102
                     Things3CLI().print_unimplemented],
103
        'repeating': ['Shows all repeating tasks',
104
                      Things3CLI().print_unimplemented],
105
        'schedule': ['Schedule an event by creating a number of related tasks',
106
                     Things3CLI().print_unimplemented],
107
        'search': ['Searches for a specific task',
108
                   Things3CLI().print_unimplemented],
109
        'stat': ['Provides a number of statistics about all tasks',
110
                 Things3CLI().print_unimplemented],
111
        'statcsv': ['Exports some statistics as semicolon separated values',
112
                    Things3CLI().print_unimplemented],
113
        'subtasks': ['Shows all subtasks',
114
                     Things3CLI().print_unimplemented],
115
        'tag': ['Shows all tasks with the waiting for tag',
116
                Things3CLI().print_unimplemented],
117
        'tags': ['Shows all tags ordered by their usage',
118
                 Things3CLI().print_unimplemented],
119
        'waiting': ['Shows all tasks with the waiting for tag',
120
                    Things3CLI().print_unimplemented],
121
    }
122
    CHOICES = []
123
    DOCU = ""
124
    for command in COMMANDS:
125
        CHOICES.append(command)
126
        DOCU = DOCU + command + "\t\t" + (COMMANDS[command][0]) + "\n"
127
128
    # Required positional argument
129
    PARSER.add_argument('command', choices=CHOICES,
130
                        metavar='command', help=DOCU)
131
132
    # Optional argument which requires a parameter (eg. -d test)
133
    PARSER.add_argument("-l", action="store", dest="limit_by",
134
                        help="Limit output by <number> of results")
135
    PARSER.add_argument("-w", action="store", dest="waiting_tag",
136
                        help="Set waiting/filter tag to <tag>")
137
    PARSER.add_argument("-o", action="store", dest="order_by",
138
                        help="Sort output by <column> (e.g. 'creationDate')")
139
    PARSER.add_argument("-s", action="store", dest="search",
140
                        help="String <string> to search for")
141
    PARSER.add_argument("-r", action="store", dest="range",
142
                        help="Limit CSV statistic export by <string>")
143
    PARSER.add_argument("-e", action="store", dest="eventfile",
144
                        help="Event: <filename> that contains a list of tasks")
145
    PARSER.add_argument("-t", action="store", dest="start",
146
                        help="Event: starts at <date>")
147
    PARSER.add_argument("-d", action="store", dest="duration",
148
                        help="Event: ends after <days>")
149
150
    # Specify output of "--version"
151
    PARSER.add_argument(
152
        "--version",
153
        action="version",
154
        version="%(prog)s (version {version})".format(version=__version__))
155
156
    MYARGS = PARSER.parse_args()
157
    main(MYARGS)
158