Minor bugfix and reformatting

Alexander Haselhoff 2020-05-09 12:19:58 +02:00
parent 3df109222d
commit 3837eb52bc
1 changed files with 48 additions and 40 deletions

View File

@ -26,12 +26,13 @@ def main():
parser.add_argument('--nocache', help='Disables caching data to disk for quicker syncing', action='store_true')
args = parser.parse_args()
def initialise(args):
# Set debug
if args.debug:
log_level = logging.DEBUG
else:
log_level = logging.INFO
logging.basicConfig(level=log_level)
logging.basicConfig(filename='DEBUG.log', level=log_level)
# Check we have a API key
if not args.api_key:
@ -59,6 +60,8 @@ def main():
logging.error("Label \'%s\' doesn't exist, please create it or change TODOIST_NEXT_ACTION_LABEL.", args.label)
sys.exit(1)
return api, label_id
def get_type(object,key):
len_suffix = [len(args.parallel_suffix), len(args.serial_suffix)]
@ -121,10 +124,13 @@ def main():
def remove_label(item, label):
if label in item['labels']:
labels = item['labels']
logging.debug('Updating \'%s\' without label', item['content'])
logging.debug('Removing \'%s\' of its label', item['content'])
labels.remove(label)
api.items.update(item['id'], labels=labels)
# Initialise api
api, label_id = initialise(args)
# Main loop
while True:
try:
@ -150,7 +156,7 @@ def main():
items = sorted(items, key=lambda x: (x['parent_id'], x['child_order']))
items = list(filter(lambda x: not x['content'].startswith('*'), items))
# If project type has been changed, clean everything foor good measure
# If project type has been changed, clean everything for good measure
if project_type_changed == 1:
[remove_label(item, label_id) for item in items]
@ -182,7 +188,8 @@ def main():
if item_type is None:
item_type = project_type
# Add labels to top items
# Add labels to top items if they have no childern
if len(child_items) == 0:
if item['parent_id'] == 0:
if project_type == 'serial':
if not first_found:
@ -193,6 +200,7 @@ def main():
elif project_type == 'parallel':
add_label(item, label_id)
else:
# If only the item type has been defined
if item_type:
add_label(item, label_id)