mirror of https://github.com/Hoffelhas/autodoist
commit
420e06abfb
1
LICENSE
1
LICENSE
|
@ -1,6 +1,7 @@
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014 Adam Kramer
|
Copyright (c) 2014 Adam Kramer
|
||||||
|
Copyright (c) 2015 Andrew Williams
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
26
README.md
26
README.md
|
@ -4,7 +4,7 @@ NextAction
|
||||||
A more GTD-like workflow for Todoist. Uses the REST API to add and remove a `@next_action` label from tasks.
|
A more GTD-like workflow for Todoist. Uses the REST API to add and remove a `@next_action` label from tasks.
|
||||||
|
|
||||||
This program looks at every list in your Todoist account.
|
This program looks at every list in your Todoist account.
|
||||||
Any list that ends with `-` or `=` is treated specially, and processed by NextAction.
|
Any list that ends with `_` or `.` is treated specially, and processed by NextAction.
|
||||||
|
|
||||||
Note that NextAction requires Todoist Premium to function properly, as labels are a premium feature.
|
Note that NextAction requires Todoist Premium to function properly, as labels are a premium feature.
|
||||||
|
|
||||||
|
@ -19,36 +19,22 @@ Activating NextAction
|
||||||
|
|
||||||
Sequential list processing
|
Sequential list processing
|
||||||
--------------------------
|
--------------------------
|
||||||
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`.
|
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`.
|
||||||
Importance is determined by order in the list
|
Importance is determined by order in the list
|
||||||
|
|
||||||
Parallel list processing
|
Parallel list processing
|
||||||
------------------------
|
------------------------
|
||||||
If a list name ends with `=`, the top level of tasks will be treated as parallel `@next_action`s.
|
If a list name ends with `.`, the top level of tasks will be treated as parallel `@next_action`s.
|
||||||
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.
|
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.
|
||||||
|
|
||||||
Executing NextAction
|
Executing NextAction
|
||||||
====================
|
====================
|
||||||
|
|
||||||
You can run NexAction from any system that supports Python, and also deploy to Heroku as a constant running service
|
You can run NexAction from any system that supports Python.
|
||||||
|
|
||||||
Running NextAction
|
Running NextAction
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
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
|
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
|
||||||
|
|
||||||
TODOIST_API_KEY="XYZ" python nextaction.py
|
python nextaction.py -a <API Key>
|
||||||
|
|
||||||
Heroku Support
|
|
||||||
--------------
|
|
||||||
|
|
||||||
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
|
|
||||||
|
|
||||||
This package is ready to be pushed to a Heroku instance with minimal configuration values:
|
|
||||||
|
|
||||||
* ```TODOIST_API_KEY``` - Your Todoist API Key
|
|
||||||
* ```TODOIST_NEXT_ACTION_LABEL``` - The label to use in Todoist for next actions (defaults to next_action)
|
|
||||||
* ```TODOIST_SYNC_DELAY``` - The number of seconds to wait between syncs. (defaults to 5)
|
|
||||||
* ```TODOIST_INBOX_HANDLING``` - What method to use for the Inbox, sequence or parallel (defaults to parallel)
|
|
||||||
* ```TODODIST_PARALLEL_SUFFIX``` - What sequence of characters to use to identify parallel processed projects (defaults to =)
|
|
||||||
* ```TODODIST_SERIAL_SUFFIX``` - What sequence of characters to use to identify serial processed projects (defaults to -)
|
|
||||||
|
|
37
app.json
37
app.json
|
@ -1,37 +0,0 @@
|
||||||
{
|
|
||||||
"name": "NextAction",
|
|
||||||
"description": "Todoist API application to provide a auto-populated next action label",
|
|
||||||
"repository": "https://github.com/nikdoof/NextAction",
|
|
||||||
"keywords": ["python"],
|
|
||||||
"env": {
|
|
||||||
"TODOIST_API_KEY": {
|
|
||||||
"description": "Your Todoist API Key",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"TODOIST_NEXT_ACTION_LABEL": {
|
|
||||||
"description": "The Todoist label to use for next actions.",
|
|
||||||
"value": "next_action",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"TODOIST_SYNC_DELAY": {
|
|
||||||
"description": "The number of seconds to wait between syncs.",
|
|
||||||
"value": "5",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"TODOIST_INBOX_HANDLING": {
|
|
||||||
"description": "What method to use for the Inbox, sequence or parallel",
|
|
||||||
"value": "parallel",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"TODODIST_PARALLEL_SUFFIX": {
|
|
||||||
"description": "What sequence of characters to use to identify parallel processed projects",
|
|
||||||
"value": "=",
|
|
||||||
"required": false
|
|
||||||
},
|
|
||||||
"TODODIST_SERIAL_SUFFIX": {
|
|
||||||
"description": "What sequence of characters to use to identify serial processed projects",
|
|
||||||
"value": "-",
|
|
||||||
"required": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import time
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import argparse
|
import argparse
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
# noinspection PyPackageRequirements
|
||||||
from todoist.api import TodoistAPI
|
from todoist.api import TodoistAPI
|
||||||
|
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def get_subitems(items, parent_item=None):
|
def get_subitems(items, parent_item=None):
|
||||||
"""Search a flat item list for child items"""
|
"""Search a flat item list for child items"""
|
||||||
|
@ -34,24 +35,20 @@ def get_subitems(items, parent_item=None):
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-a', '--api_key', help='Todoist API Key',
|
parser.add_argument('-a', '--api_key', help='Todoist API Key')
|
||||||
default=os.environ.get('TODOIST_API_KEY', None))
|
parser.add_argument('-l', '--label', help='The next action label to use', default='next_action')
|
||||||
parser.add_argument('-l', '--label', help='The next action label to use',
|
parser.add_argument('-d', '--delay', help='Specify the delay in seconds between syncs', default=5, type=int)
|
||||||
default=os.environ.get('TODOIST_NEXT_ACTION_LABEL', 'next_action'))
|
|
||||||
parser.add_argument('-d', '--delay', help='Specify the delay in seconds between syncs',
|
|
||||||
default=int(os.environ.get('TODOIST_SYNC_DELAY', '5')), type=int)
|
|
||||||
parser.add_argument('--debug', help='Enable debugging', action='store_true')
|
parser.add_argument('--debug', help='Enable debugging', action='store_true')
|
||||||
parser.add_argument('--inbox', help='The method the Inbox project should be processed',
|
parser.add_argument('--inbox', help='The method the Inbox project should be processed',
|
||||||
default=os.environ.get('TODOIST_INBOX_HANDLING', 'parallel'),
|
default='parallel', choices=['parallel', 'serial'])
|
||||||
choices=['parallel', 'serial'])
|
parser.add_argument('--parallel_suffix', default='.')
|
||||||
parser.add_argument('--parallel_suffix', default=os.environ.get('TODOIST_PARALLEL_SUFFIX', '='))
|
parser.add_argument('--serial_suffix', default='_')
|
||||||
parser.add_argument('--serial_suffix', default=os.environ.get('TODOIST_SERIAL_SUFFIX', '-'))
|
|
||||||
parser.add_argument('--hide_future', help='Hide future dated next actions until the specified number of days',
|
parser.add_argument('--hide_future', help='Hide future dated next actions until the specified number of days',
|
||||||
default=int(os.environ.get('TODOIST_HIDE_FUTURE', '7')), type=int)
|
default=7, type=int)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Set debug
|
# Set debug
|
||||||
if args.debug or os.environ.get('TODOIST_DEBUG', None):
|
if args.debug:
|
||||||
log_level = logging.DEBUG
|
log_level = logging.DEBUG
|
||||||
else:
|
else:
|
||||||
log_level = logging.INFO
|
log_level = logging.INFO
|
||||||
|
@ -89,47 +86,51 @@ def main():
|
||||||
|
|
||||||
# Main loop
|
# Main loop
|
||||||
while True:
|
while True:
|
||||||
api.sync(resource_types=['projects', 'labels', 'items'])
|
try:
|
||||||
for project in api.projects.all():
|
api.sync(resource_types=['projects', 'labels', 'items'])
|
||||||
project_type = get_project_type(project)
|
except Exception as e:
|
||||||
if project_type:
|
logging.exception('Error trying to sync with Todoist API: %s' % str(e))
|
||||||
logging.debug('Project %s being processed as %s', project['name'], project_type)
|
else:
|
||||||
|
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)
|
||||||
|
|
||||||
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['item_order'])
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
labels = item['labels']
|
labels = item['labels']
|
||||||
|
|
||||||
# If its too far in the future, remove the next_action tag and skip
|
# If its too far in the future, remove the next_action tag and skip
|
||||||
if args.hide_future > 0 and 'due_date_utc' in item.data and item['due_date_utc'] is not None:
|
if args.hide_future > 0 and 'due_date_utc' in item.data and item['due_date_utc'] is not None:
|
||||||
due_date = datetime.strptime(item['due_date_utc'], '%a %d %b %Y %H:%M:%S +0000')
|
due_date = datetime.strptime(item['due_date_utc'], '%a %d %b %Y %H:%M:%S +0000')
|
||||||
future_diff = (due_date - datetime.utcnow()).total_seconds()
|
future_diff = (due_date - datetime.utcnow()).total_seconds()
|
||||||
if future_diff >= (args.hide_future * 86400):
|
if future_diff >= (args.hide_future * 86400):
|
||||||
if label_id in labels:
|
if label_id in labels:
|
||||||
labels.remove(label_id)
|
labels.remove(label_id)
|
||||||
logging.debug('Updating %s without label as its too far in the future', item['content'])
|
logging.debug('Updating %s without label as its too far in the future', item['content'])
|
||||||
item.update(labels=labels)
|
item.update(labels=labels)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Process item
|
# Process item
|
||||||
if project_type == 'serial':
|
if project_type == 'serial':
|
||||||
if item['item_order'] == 1:
|
if item['item_order'] == 1:
|
||||||
|
if label_id not in labels:
|
||||||
|
labels.append(label_id)
|
||||||
|
logging.debug('Updating %s with label', item['content'])
|
||||||
|
item.update(labels=labels)
|
||||||
|
else:
|
||||||
|
if label_id in labels:
|
||||||
|
labels.remove(label_id)
|
||||||
|
logging.debug('Updating %s without label', item['content'])
|
||||||
|
item.update(labels=labels)
|
||||||
|
elif project_type == 'parallel':
|
||||||
if label_id not in labels:
|
if label_id not in labels:
|
||||||
labels.append(label_id)
|
|
||||||
logging.debug('Updating %s with label', item['content'])
|
logging.debug('Updating %s with label', item['content'])
|
||||||
|
labels.append(label_id)
|
||||||
item.update(labels=labels)
|
item.update(labels=labels)
|
||||||
else:
|
|
||||||
if label_id in labels:
|
|
||||||
labels.remove(label_id)
|
|
||||||
logging.debug('Updating %s without label', item['content'])
|
|
||||||
item.update(labels=labels)
|
|
||||||
elif project_type == 'parallel':
|
|
||||||
if label_id not in labels:
|
|
||||||
logging.debug('Updating %s with label', item['content'])
|
|
||||||
labels.append(label_id)
|
|
||||||
item.update(labels=labels)
|
|
||||||
|
|
||||||
api.commit()
|
api.commit()
|
||||||
logging.debug('Sleeping for %d seconds', args.delay)
|
logging.debug('Sleeping for %d seconds', args.delay)
|
||||||
time.sleep(args.delay)
|
time.sleep(args.delay)
|
||||||
|
|
||||||
|
|
13
setup.py
13
setup.py
|
@ -1,8 +1,8 @@
|
||||||
from distutils.core import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='NextAction',
|
name='NextAction',
|
||||||
version='0.1',
|
version='0.2',
|
||||||
py_modules=['nextaction'],
|
py_modules=['nextaction'],
|
||||||
url='https://github.com/nikdoof/NextAction',
|
url='https://github.com/nikdoof/NextAction',
|
||||||
license='MIT',
|
license='MIT',
|
||||||
|
@ -10,8 +10,11 @@ setup(
|
||||||
author_email='andy@tensixtyone.com',
|
author_email='andy@tensixtyone.com',
|
||||||
description='A more GTD-like workflow for Todoist. Uses the REST API to add and remove a @next_action label from tasks.',
|
description='A more GTD-like workflow for Todoist. Uses the REST API to add and remove a @next_action label from tasks.',
|
||||||
entry_points={
|
entry_points={
|
||||||
"distutils.commands": [
|
"console_scripts": [
|
||||||
"nextaction = nextaction:main",
|
"nextaction=nextaction:main",
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
|
install_requires=[
|
||||||
|
'todoist-python',
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue