From 9ca82ee13e57a866ad707047d04b5353f855d1b0 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Tue, 16 Dec 2014 23:39:29 +0100 Subject: todo.py → todo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- todo | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ todo.py | 61 ------------------------------------------------------------- 2 files changed, 61 insertions(+), 61 deletions(-) create mode 100755 todo delete mode 100755 todo.py diff --git a/todo b/todo new file mode 100755 index 0000000..3ef47e4 --- /dev/null +++ b/todo @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +""" +Usage: todo [--priority | --date] [--reverse] + +Options: + -p --priority Sort by priority + -d --date Sort by date + -r --reverse Reverse sort order + -h --help Show this screen. + -v --version Show version. +""" + +from sys import exit +from collections import OrderedDict +from docopt import docopt +import pytoml + + +def sort_toml(toml_dict, sort_key, rev=False): + return sorted( + list(toml_dict.items()), + key=lambda d: (sort_key not in d[1], d[1].get(sort_key, None)), + reverse=rev) + +def main(): + arguments = docopt(__doc__, version='todo 0.0.1.alpha') + print(arguments) + if arguments['--date']: + sort_key = 'date' + elif arguments['--priority']: + sort_key = 'priority' + else: + sort_key = 'priority' + rev = arguments['--reverse'] + + with open("/home/kyrias/documents/notes/TODO.toml", "rt") as in_file: + tasks = in_file.read() + + unsorted = OrderedDict(sorted(pytoml.loads(tasks).items())) + sorted_toml = OrderedDict(sort_toml(unsorted, sort_key, rev)) + + print(sorted_toml) + + for t_id in sorted_toml: + task = sorted_toml[t_id] + output = "{}. ".format(t_id) + if 'priority' in task: + output += "({}) ".format(task['priority']) + if 'date' in task: + output += "{}".format(task['date']) + if 'description' in task: + output += "\n {}".format(task['description']) + if 'url' in task: + output += "\n URL: {}".format(task['url']) + if 'context' in task: + output += "\n Contexts: {}".format(task['context']) + + print(output) + +if __name__ == '__main__': + main() diff --git a/todo.py b/todo.py deleted file mode 100755 index 3ef47e4..0000000 --- a/todo.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python3 -""" -Usage: todo [--priority | --date] [--reverse] - -Options: - -p --priority Sort by priority - -d --date Sort by date - -r --reverse Reverse sort order - -h --help Show this screen. - -v --version Show version. -""" - -from sys import exit -from collections import OrderedDict -from docopt import docopt -import pytoml - - -def sort_toml(toml_dict, sort_key, rev=False): - return sorted( - list(toml_dict.items()), - key=lambda d: (sort_key not in d[1], d[1].get(sort_key, None)), - reverse=rev) - -def main(): - arguments = docopt(__doc__, version='todo 0.0.1.alpha') - print(arguments) - if arguments['--date']: - sort_key = 'date' - elif arguments['--priority']: - sort_key = 'priority' - else: - sort_key = 'priority' - rev = arguments['--reverse'] - - with open("/home/kyrias/documents/notes/TODO.toml", "rt") as in_file: - tasks = in_file.read() - - unsorted = OrderedDict(sorted(pytoml.loads(tasks).items())) - sorted_toml = OrderedDict(sort_toml(unsorted, sort_key, rev)) - - print(sorted_toml) - - for t_id in sorted_toml: - task = sorted_toml[t_id] - output = "{}. ".format(t_id) - if 'priority' in task: - output += "({}) ".format(task['priority']) - if 'date' in task: - output += "{}".format(task['date']) - if 'description' in task: - output += "\n {}".format(task['description']) - if 'url' in task: - output += "\n URL: {}".format(task['url']) - if 'context' in task: - output += "\n Contexts: {}".format(task['context']) - - print(output) - -if __name__ == '__main__': - main() -- cgit v1.2.3-70-g09d2