forked from mirrors/autodoist
Add support for ignoring future dated items.
parent
52aff18d90
commit
54f770f5f7
|
@ -5,6 +5,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from todoist.api import TodoistAPI
|
from todoist.api import TodoistAPI
|
||||||
|
|
||||||
|
@ -45,6 +46,8 @@ def main():
|
||||||
choices=['parallel', 'serial'])
|
choices=['parallel', 'serial'])
|
||||||
parser.add_argument('--parallel_suffix', default=os.environ.get('TODOIST_PARALLEL_SUFFIX', '='))
|
parser.add_argument('--parallel_suffix', default=os.environ.get('TODOIST_PARALLEL_SUFFIX', '='))
|
||||||
parser.add_argument('--serial_suffix', default=os.environ.get('TODOIST_SERIAL_SUFFIX', '-'))
|
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',
|
||||||
|
default=int(os.environ.get('TODOIST_HIDE_FUTURE', '7')), type=int)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Set debug
|
# Set debug
|
||||||
|
@ -92,24 +95,24 @@ def main():
|
||||||
if project_type:
|
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)
|
||||||
|
|
||||||
# Parallel
|
items = sorted(api.items.all(lambda x: x['project_id'] == project['id']), key=lambda x: x['item_order'])
|
||||||
if project_type == 'parallel':
|
|
||||||
items = api.items.all(lambda x: x['project_id'] == project['id'])
|
for item in items:
|
||||||
for item in items:
|
labels = item['labels']
|
||||||
labels = item['labels']
|
|
||||||
if label_id not in labels:
|
# If its too far in the future, remove the next_action tag and skip
|
||||||
logging.debug('Updating %s with label', item['content'])
|
if args.hide_future > 0 and 'due_date_utc' in item.data and item['due_date_utc'] is not None:
|
||||||
labels.append(label_id)
|
due_date = datetime.strptime(item['due_date_utc'], '%a %d %b %Y %H:%M:%S +0000')
|
||||||
|
future_diff = (due_date - datetime.utcnow()).total_seconds()
|
||||||
|
if future_diff >= (args.hide_future * 86400) and label_id in labels:
|
||||||
|
labels.remove(label_id)
|
||||||
|
logging.debug('Updating %s without label as its too far in the future', item['content'])
|
||||||
item.update(labels=labels)
|
item.update(labels=labels)
|
||||||
|
continue
|
||||||
|
|
||||||
# Serial
|
# Process item
|
||||||
if project_type == 'serial':
|
if project_type == 'serial':
|
||||||
items = sorted(api.items.all(lambda x: x['project_id'] == project['id']),
|
|
||||||
key=lambda x: x['item_order'])
|
|
||||||
for item in items:
|
|
||||||
labels = item['labels']
|
|
||||||
if item['item_order'] == 1:
|
if item['item_order'] == 1:
|
||||||
|
|
||||||
if label_id not in labels:
|
if label_id not in labels:
|
||||||
labels.append(label_id)
|
labels.append(label_id)
|
||||||
logging.debug('Updating %s with label', item['content'])
|
logging.debug('Updating %s with label', item['content'])
|
||||||
|
@ -119,6 +122,11 @@ def main():
|
||||||
labels.remove(label_id)
|
labels.remove(label_id)
|
||||||
logging.debug('Updating %s without label', item['content'])
|
logging.debug('Updating %s without label', item['content'])
|
||||||
item.update(labels=labels)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue