From 7a24f83827929a509f6ea626d074c0653285201f Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 4 Aug 2016 10:38:16 +0100 Subject: [PATCH 1/8] Start 0.5-dev --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d5a3152..26a221f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='NextAction', - version='0.4', + version='0.5-dev', py_modules=['nextaction'], url='https://github.com/nikdoof/NextAction', license='MIT', From 52ad1ea908eea3f9ef0d1503d7e636e29c18320d Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 4 Aug 2016 10:42:29 +0100 Subject: [PATCH 2/8] Initial v7 API changes --- nextaction.py | 6 +++--- requirements.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nextaction.py b/nextaction.py index 5aae360..e9f11b7 100755 --- a/nextaction.py +++ b/nextaction.py @@ -66,7 +66,7 @@ def main(): logging.debug('Connecting to the Todoist API') api = TodoistAPI(token=args.api_key) logging.debug('Syncing the current state from the API') - api.sync(resource_types=['projects', 'labels', 'items']) + api.sync() # Check the next action label exists labels = api.labels.all(lambda x: x['name'] == args.label) @@ -80,7 +80,7 @@ def main(): def get_project_type(project_object): """Identifies how a project should be handled.""" name = project_object['name'].strip() - if project['name'] == 'Inbox': + if name == 'Inbox': return args.inbox elif name[-1] == args.parallel_suffix: return 'parallel' @@ -112,7 +112,7 @@ def main(): # Main loop while True: try: - api.sync(resource_types=['projects', 'labels', 'items']) + api.sync() except Exception as e: logging.exception('Error trying to sync with Todoist API: %s' % str(e)) else: diff --git a/requirements.txt b/requirements.txt index 8cdf4ab..2173aea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -todoist-python==0.2.26 \ No newline at end of file +todoist-python>=7.0.10,<8.0.0 \ No newline at end of file From fa757f33d1e98fa3e6785b8381bfa447153cefae Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 4 Aug 2016 10:48:07 +0100 Subject: [PATCH 3/8] Only tag non-completed tasks in serial lists, resolves #1 --- nextaction.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nextaction.py b/nextaction.py index e9f11b7..64ab6d8 100755 --- a/nextaction.py +++ b/nextaction.py @@ -142,9 +142,11 @@ def main(): if item_type or len(child_items) > 0: # Process serial tagged items if item_type == 'serial': - for idx, child_item in enumerate(child_items): - if idx == 0: + for child_item in child_items: + first_found = False + if child_item['checked'] == 0 and not first_found: add_label(child_item, label_id) + first_found = True else: remove_label(child_item, label_id) # Process parallel tagged items or untagged parents From 73361c7f89dc2d856949aa696d9cf910a458e779 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 4 Aug 2016 11:03:10 +0100 Subject: [PATCH 4/8] Add option to disable local disk caching of the todo list --- nextaction.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nextaction.py b/nextaction.py index 64ab6d8..0d96210 100755 --- a/nextaction.py +++ b/nextaction.py @@ -48,6 +48,7 @@ def main(): parser.add_argument('--hide_future', help='Hide future dated next actions until the specified number of days', default=7, type=int) parser.add_argument('--onetime', help='Update Todoist once and exit', action='store_true') + parser.add_argument('--nocache', help='Disables caching data to disk for quicker syncing', action='store_true') args = parser.parse_args() # Set debug @@ -64,7 +65,13 @@ def main(): # Run the initial sync logging.debug('Connecting to the Todoist API') - api = TodoistAPI(token=args.api_key) + + api_arguments = {'token': args.api_key} + if args.nocache: + logging.debug('Disabling local caching') + api_arguments['cache'] = None + + api = TodoistAPI(**api_arguments) logging.debug('Syncing the current state from the API') api.sync() From fa9c01a2f6aeacd0862b631d9b1c0a3a1eddf167 Mon Sep 17 00:00:00 2001 From: shadowgate15 Date: Tue, 10 Mar 2020 12:28:58 -0500 Subject: [PATCH 5/8] Add Heroku support --- Procfile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..1cad652 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python nextaction.py \ No newline at end of file From b4997716958b720de1ee510e3b1bec4cc55bde66 Mon Sep 17 00:00:00 2001 From: shadowgate15 Date: Tue, 10 Mar 2020 12:28:58 -0500 Subject: [PATCH 6/8] Add Heroku support --- .gitignore | 4 +++- Procfile | 1 + nextaction.py | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Procfile diff --git a/.gitignore b/.gitignore index 6dd6a3d..094c669 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,6 @@ docs/_build/ target/ # IDEA -.idea/ \ No newline at end of file +.idea/ + +.env \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..d0926f0 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python nextaction.py -a $TODOIST_API_KEY -l $TODOIST_NEXT_ACTION_LABEL --debug --onetime \ No newline at end of file diff --git a/nextaction.py b/nextaction.py index 0d96210..13f608a 100755 --- a/nextaction.py +++ b/nextaction.py @@ -4,6 +4,8 @@ import logging import argparse # noinspection PyPackageRequirements +import os + from todoist.api import TodoistAPI import time From c542faadee97b8bfd02e4c7537487b05bad4a31b Mon Sep 17 00:00:00 2001 From: shadowgate15 Date: Tue, 10 Mar 2020 22:00:21 -0500 Subject: [PATCH 7/8] Update todoist-python to version 8.1.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2173aea..9e9d3d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -todoist-python>=7.0.10,<8.0.0 \ No newline at end of file +todoist-python>=8.1.1 \ No newline at end of file From 7851de590e142762c00a08cd703cb5f94eb483cd Mon Sep 17 00:00:00 2001 From: shadowgate15 Date: Tue, 10 Mar 2020 22:01:02 -0500 Subject: [PATCH 8/8] Fix errors due to upgraded todoist-python version --- nextaction.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/nextaction.py b/nextaction.py index 13f608a..2bf46e2 100755 --- a/nextaction.py +++ b/nextaction.py @@ -3,35 +3,34 @@ import logging import argparse -# noinspection PyPackageRequirements -import os - from todoist.api import TodoistAPI import time import sys from datetime import datetime +CHECKED = 1 + def get_subitems(items, parent_item=None): """Search a flat item list for child items.""" result_items = [] found = False if parent_item: - required_indent = parent_item['indent'] + 1 + required_parent_id = parent_item['parent_id'] + 1 else: - required_indent = 1 + required_parent_id = 1 for item in items: if parent_item: if not found and item['id'] != parent_item['id']: continue else: found = True - if item['indent'] == parent_item['indent'] and item['id'] != parent_item['id']: + if item['parent_id'] == parent_item['parent_id'] and item['id'] != parent_item['id']: return result_items - elif item['indent'] == required_indent and found: + elif item['parent_id'] == required_parent_id and found: result_items.append(item) - elif item['indent'] == required_indent: + elif item['parent_id'] == required_parent_id: result_items.append(item) return result_items @@ -81,9 +80,9 @@ def main(): labels = api.labels.all(lambda x: x['name'] == args.label) if len(labels) > 0: label_id = labels[0]['id'] - logging.debug('Label %s found as label id %d', args.label, label_id) + logging.debug('Label \'%s\' found as label id %d', args.label, label_id) else: - logging.error("Label %s doesn't exist, please create it or change TODOIST_NEXT_ACTION_LABEL.", args.label) + logging.error("Label \'%s\' doesn't exist, please create it or change TODOIST_NEXT_ACTION_LABEL.", args.label) sys.exit(1) def get_project_type(project_object): @@ -107,14 +106,14 @@ def main(): def add_label(item, label): if label not in item['labels']: labels = item['labels'] - logging.debug('Updating %s with label', item['content']) + logging.debug('Updating \'%s\' with label', item['content']) labels.append(label) api.items.update(item['id'], labels=labels) def remove_label(item, label): if label in item['labels']: labels = item['labels'] - logging.debug('Updating %s without label', item['content']) + logging.debug('Updating \'%s\' without label', item['content']) labels.remove(label) api.items.update(item['id'], labels=labels) @@ -128,10 +127,11 @@ def main(): for project in api.projects.all(): project_type = get_project_type(project) if project_type: - logging.debug('Project %s being processed as %s', project['name'], project_type) + logging.debug('Project \'%s\' being processed as %s', project['name'], project_type) # Get all items for the project, sort by the item_order field. - items = sorted(api.items.all(lambda x: x['project_id'] == project['id']), key=lambda x: x['item_order']) + items = sorted(api.items.all(lambda x: x['project_id'] == project['id']), + key=lambda x: x['child_order']) for item in items: @@ -144,15 +144,17 @@ def main(): continue item_type = get_item_type(item) - child_items = get_subitems(items, item) + # child_items = get_subitems(items, item) + child_items = sorted(list(filter(lambda x: x['parent_id'] == item['id'], items)), + key=lambda x: x['child_order']) if item_type: - logging.debug('Identified %s as %s type', item['content'], item_type) + logging.debug('Identified \'%s\' as %s type', item['content'], item_type) if item_type or len(child_items) > 0: # Process serial tagged items if item_type == 'serial': + first_found = False for child_item in child_items: - first_found = False if child_item['checked'] == 0 and not first_found: add_label(child_item, label_id) first_found = True @@ -166,11 +168,11 @@ def main(): # Remove the label from the parent remove_label(item, label_id) - # Process items as per project type on indent 1 if untagged + # Process items(w/ project as parent and no children) per project type else: - if item['indent'] == 1: + if item['parent_id'] is None: if project_type == 'serial': - if item['item_order'] == 1: + if item['child_order'] == 1: add_label(item, label_id) else: remove_label(item, label_id)