Skip to content
This repository was archived by the owner on Feb 25, 2018. It is now read-only.

Commit 420e06a

Browse files
committed
Merge branch 'feature/0.2'
2 parents 5554c63 + 3bf53c7 commit 420e06a

6 files changed

Lines changed: 69 additions & 116 deletions

File tree

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2014 Adam Kramer
4+
Copyright (c) 2015 Andrew Williams
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ NextAction
44
A more GTD-like workflow for Todoist. Uses the REST API to add and remove a `@next_action` label from tasks.
55

66
This program looks at every list in your Todoist account.
7-
Any list that ends with `-` or `=` is treated specially, and processed by NextAction.
7+
Any list that ends with `_` or `.` is treated specially, and processed by NextAction.
88

99
Note that NextAction requires Todoist Premium to function properly, as labels are a premium feature.
1010

@@ -19,36 +19,22 @@ Activating NextAction
1919

2020
Sequential list processing
2121
--------------------------
22-
If a list ends with `-`, the top level of tasks will be treated as a priority queue and the most important will be labeled `@next_action`.
22+
If a list ends with `_`, the top level of tasks will be treated as a priority queue and the most important will be labeled `@next_action`.
2323
Importance is determined by order in the list
2424

2525
Parallel list processing
2626
------------------------
27-
If a list name ends with `=`, the top level of tasks will be treated as parallel `@next_action`s.
28-
The waterfall processing will be applied the same way as sequential lists - every parent task will be treated as sequential. This can be overridden by appending `=` to the name of the parent task.
27+
If a list name ends with `.`, the top level of tasks will be treated as parallel `@next_action`s.
28+
The waterfall processing will be applied the same way as sequential lists - every parent task will be treated as sequential. This can be overridden by appending `_` to the name of the parent task.
2929

3030
Executing NextAction
3131
====================
3232

33-
You can run NexAction from any system that supports Python, and also deploy to Heroku as a constant running service
33+
You can run NexAction from any system that supports Python.
3434

3535
Running NextAction
3636
------------------
3737

3838
NextAction will read your environment to retrieve your Todoist API key, so to run on a Linux/Mac OSX you can use the following commandline
3939

40-
TODOIST_API_KEY="XYZ" python nextaction.py
41-
42-
Heroku Support
43-
--------------
44-
45-
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
46-
47-
This package is ready to be pushed to a Heroku instance with minimal configuration values:
48-
49-
* ```TODOIST_API_KEY``` - Your Todoist API Key
50-
* ```TODOIST_NEXT_ACTION_LABEL``` - The label to use in Todoist for next actions (defaults to next_action)
51-
* ```TODOIST_SYNC_DELAY``` - The number of seconds to wait between syncs. (defaults to 5)
52-
* ```TODOIST_INBOX_HANDLING``` - What method to use for the Inbox, sequence or parallel (defaults to parallel)
53-
* ```TODODIST_PARALLEL_SUFFIX``` - What sequence of characters to use to identify parallel processed projects (defaults to =)
54-
* ```TODODIST_SERIAL_SUFFIX``` - What sequence of characters to use to identify serial processed projects (defaults to -)
40+
python nextaction.py -a <API Key>

app.json

Lines changed: 0 additions & 37 deletions
This file was deleted.

nextaction.py

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env python
22

3-
import time
43
import logging
5-
import os
6-
import sys
74
import argparse
8-
from datetime import datetime
95

6+
# noinspection PyPackageRequirements
107
from todoist.api import TodoistAPI
118

9+
import time
10+
import sys
11+
from datetime import datetime
12+
1213

1314
def get_subitems(items, parent_item=None):
1415
"""Search a flat item list for child items"""
@@ -34,24 +35,20 @@ def get_subitems(items, parent_item=None):
3435
def main():
3536

3637
parser = argparse.ArgumentParser()
37-
parser.add_argument('-a', '--api_key', help='Todoist API Key',
38-
default=os.environ.get('TODOIST_API_KEY', None))
39-
parser.add_argument('-l', '--label', help='The next action label to use',
40-
default=os.environ.get('TODOIST_NEXT_ACTION_LABEL', 'next_action'))
41-
parser.add_argument('-d', '--delay', help='Specify the delay in seconds between syncs',
42-
default=int(os.environ.get('TODOIST_SYNC_DELAY', '5')), type=int)
38+
parser.add_argument('-a', '--api_key', help='Todoist API Key')
39+
parser.add_argument('-l', '--label', help='The next action label to use', default='next_action')
40+
parser.add_argument('-d', '--delay', help='Specify the delay in seconds between syncs', default=5, type=int)
4341
parser.add_argument('--debug', help='Enable debugging', action='store_true')
4442
parser.add_argument('--inbox', help='The method the Inbox project should be processed',
45-
default=os.environ.get('TODOIST_INBOX_HANDLING', 'parallel'),
46-
choices=['parallel', 'serial'])
47-
parser.add_argument('--parallel_suffix', default=os.environ.get('TODOIST_PARALLEL_SUFFIX', '='))
48-
parser.add_argument('--serial_suffix', default=os.environ.get('TODOIST_SERIAL_SUFFIX', '-'))
43+
default='parallel', choices=['parallel', 'serial'])
44+
parser.add_argument('--parallel_suffix', default='.')
45+
parser.add_argument('--serial_suffix', default='_')
4946
parser.add_argument('--hide_future', help='Hide future dated next actions until the specified number of days',
50-
default=int(os.environ.get('TODOIST_HIDE_FUTURE', '7')), type=int)
47+
default=7, type=int)
5148
args = parser.parse_args()
5249

5350
# Set debug
54-
if args.debug or os.environ.get('TODOIST_DEBUG', None):
51+
if args.debug:
5552
log_level = logging.DEBUG
5653
else:
5754
log_level = logging.INFO
@@ -89,47 +86,51 @@ def get_project_type(project_object):
8986

9087
# Main loop
9188
while True:
92-
api.sync(resource_types=['projects', 'labels', 'items'])
93-
for project in api.projects.all():
94-
project_type = get_project_type(project)
95-
if project_type:
96-
logging.debug('Project %s being processed as %s', project['name'], project_type)
97-
98-
items = sorted(api.items.all(lambda x: x['project_id'] == project['id']), key=lambda x: x['item_order'])
99-
100-
for item in items:
101-
labels = item['labels']
102-
103-
# If its too far in the future, remove the next_action tag and skip
104-
if args.hide_future > 0 and 'due_date_utc' in item.data and item['due_date_utc'] is not None:
105-
due_date = datetime.strptime(item['due_date_utc'], '%a %d %b %Y %H:%M:%S +0000')
106-
future_diff = (due_date - datetime.utcnow()).total_seconds()
107-
if future_diff >= (args.hide_future * 86400):
108-
if label_id in labels:
109-
labels.remove(label_id)
110-
logging.debug('Updating %s without label as its too far in the future', item['content'])
111-
item.update(labels=labels)
112-
continue
113-
114-
# Process item
115-
if project_type == 'serial':
116-
if item['item_order'] == 1:
89+
try:
90+
api.sync(resource_types=['projects', 'labels', 'items'])
91+
except Exception as e:
92+
logging.exception('Error trying to sync with Todoist API: %s' % str(e))
93+
else:
94+
for project in api.projects.all():
95+
project_type = get_project_type(project)
96+
if project_type:
97+
logging.debug('Project %s being processed as %s', project['name'], project_type)
98+
99+
items = sorted(api.items.all(lambda x: x['project_id'] == project['id']), key=lambda x: x['item_order'])
100+
101+
for item in items:
102+
labels = item['labels']
103+
104+
# If its too far in the future, remove the next_action tag and skip
105+
if args.hide_future > 0 and 'due_date_utc' in item.data and item['due_date_utc'] is not None:
106+
due_date = datetime.strptime(item['due_date_utc'], '%a %d %b %Y %H:%M:%S +0000')
107+
future_diff = (due_date - datetime.utcnow()).total_seconds()
108+
if future_diff >= (args.hide_future * 86400):
109+
if label_id in labels:
110+
labels.remove(label_id)
111+
logging.debug('Updating %s without label as its too far in the future', item['content'])
112+
item.update(labels=labels)
113+
continue
114+
115+
# Process item
116+
if project_type == 'serial':
117+
if item['item_order'] == 1:
118+
if label_id not in labels:
119+
labels.append(label_id)
120+
logging.debug('Updating %s with label', item['content'])
121+
item.update(labels=labels)
122+
else:
123+
if label_id in labels:
124+
labels.remove(label_id)
125+
logging.debug('Updating %s without label', item['content'])
126+
item.update(labels=labels)
127+
elif project_type == 'parallel':
117128
if label_id not in labels:
118-
labels.append(label_id)
119129
logging.debug('Updating %s with label', item['content'])
130+
labels.append(label_id)
120131
item.update(labels=labels)
121-
else:
122-
if label_id in labels:
123-
labels.remove(label_id)
124-
logging.debug('Updating %s without label', item['content'])
125-
item.update(labels=labels)
126-
elif project_type == 'parallel':
127-
if label_id not in labels:
128-
logging.debug('Updating %s with label', item['content'])
129-
labels.append(label_id)
130-
item.update(labels=labels)
131132

132-
api.commit()
133+
api.commit()
133134
logging.debug('Sleeping for %d seconds', args.delay)
134135
time.sleep(args.delay)
135136

setup.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
from distutils.core import setup
1+
from setuptools import setup
22

33
setup(
44
name='NextAction',
5-
version='0.1',
5+
version='0.2',
66
py_modules=['nextaction'],
77
url='https://github.com/nikdoof/NextAction',
88
license='MIT',
99
author='Andrew Williams',
1010
author_email='[email protected]',
1111
description='A more GTD-like workflow for Todoist. Uses the REST API to add and remove a @next_action label from tasks.',
1212
entry_points={
13-
"distutils.commands": [
14-
"nextaction = nextaction:main",
13+
"console_scripts": [
14+
"nextaction=nextaction:main",
1515
],
16-
}
16+
},
17+
install_requires=[
18+
'todoist-python',
19+
]
1720
)

0 commit comments

Comments
 (0)