forked from mirrors/autodoist
Added logic to header or unheader multiple items, specifiec from project, section, or top item level
parent
346702b904
commit
ecbe8a28fa
102
autodoist.py
102
autodoist.py
|
@ -251,6 +251,8 @@ def main():
|
||||||
# Scan the end of a name to find what type it is
|
# Scan the end of a name to find what type it is
|
||||||
def get_type(object, key):
|
def get_type(object, key):
|
||||||
|
|
||||||
|
object_name = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
old_type = object[key]
|
old_type = object[key]
|
||||||
except:
|
except:
|
||||||
|
@ -260,7 +262,10 @@ def main():
|
||||||
try:
|
try:
|
||||||
object_name = object['name'].strip()
|
object_name = object['name'].strip()
|
||||||
except:
|
except:
|
||||||
object_name = object['content'].strip()
|
try:
|
||||||
|
object_name = object['content'].strip()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
current_type = check_name(object_name)
|
current_type = check_name(object_name)
|
||||||
|
|
||||||
|
@ -335,7 +340,7 @@ def main():
|
||||||
overview_item_ids[str(item['id'])] = -1
|
overview_item_ids[str(item['id'])] = -1
|
||||||
overview_item_labels[str(item['id'])] = labels
|
overview_item_labels[str(item['id'])] = labels
|
||||||
|
|
||||||
# Ensure labels are only issued once
|
# Ensure labels are only issued once per item
|
||||||
def update_labels(label_id):
|
def update_labels(label_id):
|
||||||
filtered_overview_ids = [
|
filtered_overview_ids = [
|
||||||
k for k, v in overview_item_ids.items() if v != 0]
|
k for k, v in overview_item_ids.items() if v != 0]
|
||||||
|
@ -352,6 +357,40 @@ def main():
|
||||||
}
|
}
|
||||||
return none_sec
|
return none_sec
|
||||||
|
|
||||||
|
def check_header(level):
|
||||||
|
header_all_in_level = False
|
||||||
|
unheader_all_in_level = False
|
||||||
|
method = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
name = level['name']
|
||||||
|
method = 1
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
content = level['content']
|
||||||
|
method = 2
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if method == 1:
|
||||||
|
if name[:3] == '** ':
|
||||||
|
header_all_in_level = True
|
||||||
|
level.update(name=name[3:])
|
||||||
|
if name[:3] == '!* ':
|
||||||
|
unheader_all_in_level = True
|
||||||
|
level.update(name=name[3:])
|
||||||
|
elif method == 2:
|
||||||
|
if content[:3] == '** ':
|
||||||
|
header_all_in_level = True
|
||||||
|
level.update(content=content[3:])
|
||||||
|
if content[:3] == '!* ':
|
||||||
|
unheader_all_in_level = True
|
||||||
|
level.update(content=content[3:])
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return header_all_in_level, unheader_all_in_level
|
||||||
|
|
||||||
# Check for updates
|
# Check for updates
|
||||||
check_for_update(current_version)
|
check_for_update(current_version)
|
||||||
|
|
||||||
|
@ -371,15 +410,7 @@ def main():
|
||||||
first_found_project = False
|
first_found_project = False
|
||||||
|
|
||||||
# Check if we need to (un)header entire project
|
# Check if we need to (un)header entire project
|
||||||
header_project = False
|
header_all_in_p, unheader_all_in_p = check_header(project)
|
||||||
unheader_project = False
|
|
||||||
|
|
||||||
if project['name'][:2] == '**':
|
|
||||||
header_project = True
|
|
||||||
project.update(name=project['name'][3:])
|
|
||||||
if project['name'][:2] == '!*':
|
|
||||||
unheader_project = True
|
|
||||||
project.update(name=project['name'][3:])
|
|
||||||
|
|
||||||
if label_id is not None:
|
if label_id is not None:
|
||||||
# Get project type
|
# Get project type
|
||||||
|
@ -399,6 +430,9 @@ def main():
|
||||||
|
|
||||||
for section in sections:
|
for section in sections:
|
||||||
|
|
||||||
|
# Check if we need to (un)header entire secion
|
||||||
|
header_all_in_s, unheader_all_in_s = check_header(section)
|
||||||
|
|
||||||
# To determine if a sequential task was found
|
# To determine if a sequential task was found
|
||||||
first_found_section = False
|
first_found_section = False
|
||||||
|
|
||||||
|
@ -408,12 +442,9 @@ def main():
|
||||||
logging.debug('Identified \'%s\' as %s type',
|
logging.debug('Identified \'%s\' as %s type',
|
||||||
section['name'], section_type)
|
section['name'], section_type)
|
||||||
|
|
||||||
# Get all items for the section
|
# Get all items for the section
|
||||||
|
|
||||||
items = [x for x in project_items if x['section_id'] == section['id']]
|
items = [x for x in project_items if x['section_id'] == section['id']]
|
||||||
# items = api.items.all(lambda x: x['section_id'] == section['id'])
|
|
||||||
# sections = [x['section_id'] for x in items] # better than api.sections.all(lambda x: x['project_id'] == project['id']), since then NoneTypes are not shown
|
|
||||||
|
|
||||||
# Change top parents_id in order to sort later on
|
# Change top parents_id in order to sort later on
|
||||||
for item in items:
|
for item in items:
|
||||||
if not item['parent_id']:
|
if not item['parent_id']:
|
||||||
|
@ -422,28 +453,15 @@ def main():
|
||||||
# Sort by parent_id and filter for completable items
|
# Sort by parent_id and filter for completable items
|
||||||
items = sorted(items, key=lambda x: (
|
items = sorted(items, key=lambda x: (
|
||||||
x['parent_id'], x['child_order']))
|
x['parent_id'], x['child_order']))
|
||||||
items = list(
|
|
||||||
filter(lambda x: not x['content'].startswith('*'), items))
|
# If a type has changed, clean label for good measure
|
||||||
header_items = list(
|
|
||||||
filter(lambda x: x['content'].startswith('*'), items))
|
|
||||||
|
|
||||||
if label_id is not None:
|
if label_id is not None:
|
||||||
# If some type has been changed, clean everything for good measure
|
|
||||||
if project_type_changed == 1 or section_type_changed == 1:
|
if project_type_changed == 1 or section_type_changed == 1:
|
||||||
# Remove labels
|
# Remove labels
|
||||||
[remove_label(item, label_id) for item in items]
|
[remove_label(item, label_id) for item in items]
|
||||||
# Remove parent types
|
# Remove parent types
|
||||||
for item in items:
|
for item in items:
|
||||||
item['parent_type'] = None
|
item['parent_type'] = None
|
||||||
|
|
||||||
for items in header_items:
|
|
||||||
# Logic for applying headers
|
|
||||||
if header_project is True: #TODO add section or item
|
|
||||||
if item['content'][0] != '*':
|
|
||||||
item.update(content='* ' + item['content'])
|
|
||||||
if unheader_project is True: #TODO add section or item
|
|
||||||
if item['content'][0] == '*':
|
|
||||||
item.update(content=item['content'][3:])
|
|
||||||
|
|
||||||
# For all items in this section
|
# For all items in this section
|
||||||
for item in items:
|
for item in items:
|
||||||
|
@ -457,6 +475,23 @@ def main():
|
||||||
child_items = list(
|
child_items = list(
|
||||||
filter(lambda x: x['parent_id'] == item['id'], non_checked_items))
|
filter(lambda x: x['parent_id'] == item['id'], non_checked_items))
|
||||||
|
|
||||||
|
# Check if we need to (un)header entire item tree
|
||||||
|
header_all_in_i, unheader_all_in_i = check_header(item)
|
||||||
|
|
||||||
|
# Logic for applying and removing headers
|
||||||
|
if any([header_all_in_p, header_all_in_s, header_all_in_i]):
|
||||||
|
if item['content'][0] != '*':
|
||||||
|
item.update(content='* ' + item['content'])
|
||||||
|
for ci in child_items:
|
||||||
|
if not ci['content'].startswith('*'):
|
||||||
|
ci.update(content='* ' + ci['content'])
|
||||||
|
|
||||||
|
if any([unheader_all_in_p, unheader_all_in_s]):
|
||||||
|
if item['content'][0] == '*':
|
||||||
|
item.update(content=item['content'][2:])
|
||||||
|
if unheader_all_in_i:
|
||||||
|
[ci.update(content=ci['content'][2:]) for ci in child_items]
|
||||||
|
|
||||||
# Logic for recurring lists
|
# Logic for recurring lists
|
||||||
if not args.recurring:
|
if not args.recurring:
|
||||||
try:
|
try:
|
||||||
|
@ -557,9 +592,11 @@ def main():
|
||||||
|
|
||||||
# If options turned on, start labelling logic
|
# If options turned on, start labelling logic
|
||||||
if label_id is not None:
|
if label_id is not None:
|
||||||
# Skip processing an item if it has already been checked
|
# Skip processing an item if it has already been checked or is a header
|
||||||
if item['checked'] == 1:
|
if item['checked'] == 1:
|
||||||
continue
|
continue
|
||||||
|
if item['content'].startswith('*'):
|
||||||
|
continue
|
||||||
|
|
||||||
# Check item type
|
# Check item type
|
||||||
item_type, item_type_changed = get_item_type(
|
item_type, item_type_changed = get_item_type(
|
||||||
|
@ -728,6 +765,7 @@ def main():
|
||||||
if args.onetime:
|
if args.onetime:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Set a delay before next sync
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
delta_time = end_time - start_time
|
delta_time = end_time - start_time
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue