From 70567cacf58a35b417d6aeb123353a80855aeef0 Mon Sep 17 00:00:00 2001 From: Hoffelhas Date: Sun, 6 Dec 2020 23:08:47 +0100 Subject: [PATCH] Initial modifications to include section type --- autodoist.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/autodoist.py b/autodoist.py index f238e00..4af7405 100644 --- a/autodoist.py +++ b/autodoist.py @@ -225,20 +225,9 @@ def main(): logging.error("Error while checking for updates: {}".format(e)) return 1 - def get_type(object, key): + def check_name(name): len_suffix = [len(args.pp_suffix), len(args.ss_suffix), len(args.ps_suffix), len(args.sp_suffix)] - try: - old_type = object[key] - except Exception as e: - # logging.debug('No defined project_type: %s' % str(e)) - old_type = None - - try: - name = object['name'].strip() - except: - name = object['content'].strip() - if name == 'Inbox': current_type = args.inbox elif name[-len_suffix[0]:] == args.pp_suffix: @@ -252,6 +241,33 @@ def main(): else: current_type = None + return current_type + + def get_type(object, key): + + #TODO: API variable needs to be parsed to this function in order to make this work. + + try: + old_type = object[key] + except Exception as e: + # logging.debug('No defined project_type: %s' % str(e)) + old_type = None + + try: + object_name = object['name'].strip() + except: + object_name = object['content'].strip() + + current_type = check_name(object_name) + + # If no type is found in parent tast, try to find one in the section name + if current_type is None: + try: + section_name = api.sections.all(lambda x: x['id'] == object['section_id']) + current_type = check_name(section_name) + except Exception as e: + current_type = None + # Check if project type changed with respect to previous run if old_type == current_type: type_changed = 0