Cleanups and docstrings.

master
Andrew Williams 2015-08-29 18:32:24 +01:00
parent 990b0190bc
commit 5c4945d3c2
1 changed files with 7 additions and 5 deletions

View File

@ -15,6 +15,7 @@ INBOX_HANDLING = os.environ.get('TODOIST_INBOX_HANDLING', 'parallel')
PARALLEL_SUFFIX = os.environ.get('TODOIST_PARALLEL_SUFFIX', '=') PARALLEL_SUFFIX = os.environ.get('TODOIST_PARALLEL_SUFFIX', '=')
SERIAL_SUFFIX = os.environ.get('TODOIST_SERIAL_SUFFIX', '-') SERIAL_SUFFIX = os.environ.get('TODOIST_SERIAL_SUFFIX', '-')
def get_project_type(project): def get_project_type(project):
"""Identifies how a project should be handled""" """Identifies how a project should be handled"""
name = project['name'].strip() name = project['name'].strip()
@ -27,6 +28,7 @@ def get_project_type(project):
def get_subitems(items, parent_item=None): def get_subitems(items, parent_item=None):
"""Search a flat item list for child items"""
result_items = [] result_items = []
found = False found = False
if parent_item: if parent_item:
@ -72,12 +74,12 @@ def main():
while True: while True:
api.sync(resource_types=['projects', 'labels', 'items']) api.sync(resource_types=['projects', 'labels', 'items'])
for project in api.projects.all(): for project in api.projects.all():
proj_type = get_project_type(project) project_type = get_project_type(project)
if proj_type: if project_type:
logging.debug('Project %s being processed as %s', project['name'], proj_type) logging.debug('Project %s being processed as %s', project['name'], project_type)
# Parallel # Parallel
if proj_type == 'parallel': if project_type == 'parallel':
items = api.items.all(lambda x: x['project_id'] == project['id']) 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']
@ -87,7 +89,7 @@ def main():
item.update(labels=labels) item.update(labels=labels)
# Serial # Serial
if proj_type == 'serial': if project_type == 'serial':
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']