mirror of https://github.com/Hoffelhas/autodoist
Minor bugfix and reformatting
parent
3df109222d
commit
3837eb52bc
|
@ -26,12 +26,13 @@ def main():
|
||||||
parser.add_argument('--nocache', help='Disables caching data to disk for quicker syncing', action='store_true')
|
parser.add_argument('--nocache', help='Disables caching data to disk for quicker syncing', action='store_true')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
def initialise(args):
|
||||||
# Set debug
|
# Set debug
|
||||||
if args.debug:
|
if args.debug:
|
||||||
log_level = logging.DEBUG
|
log_level = logging.DEBUG
|
||||||
else:
|
else:
|
||||||
log_level = logging.INFO
|
log_level = logging.INFO
|
||||||
logging.basicConfig(level=log_level)
|
logging.basicConfig(filename='DEBUG.log', level=log_level)
|
||||||
|
|
||||||
# Check we have a API key
|
# Check we have a API key
|
||||||
if not args.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)
|
logging.error("Label \'%s\' doesn't exist, please create it or change TODOIST_NEXT_ACTION_LABEL.", args.label)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
return api, label_id
|
||||||
|
|
||||||
def get_type(object,key):
|
def get_type(object,key):
|
||||||
len_suffix = [len(args.parallel_suffix), len(args.serial_suffix)]
|
len_suffix = [len(args.parallel_suffix), len(args.serial_suffix)]
|
||||||
|
|
||||||
|
@ -121,10 +124,13 @@ def main():
|
||||||
def remove_label(item, label):
|
def remove_label(item, label):
|
||||||
if label in item['labels']:
|
if label in item['labels']:
|
||||||
labels = 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)
|
labels.remove(label)
|
||||||
api.items.update(item['id'], labels=labels)
|
api.items.update(item['id'], labels=labels)
|
||||||
|
|
||||||
|
# Initialise api
|
||||||
|
api, label_id = initialise(args)
|
||||||
|
|
||||||
# Main loop
|
# Main loop
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -150,7 +156,7 @@ def main():
|
||||||
items = sorted(items, key=lambda x: (x['parent_id'], x['child_order']))
|
items = sorted(items, key=lambda x: (x['parent_id'], x['child_order']))
|
||||||
items = list(filter(lambda x: not x['content'].startswith('*'), items))
|
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:
|
if project_type_changed == 1:
|
||||||
[remove_label(item, label_id) for item in items]
|
[remove_label(item, label_id) for item in items]
|
||||||
|
|
||||||
|
@ -182,7 +188,8 @@ def main():
|
||||||
if item_type is None:
|
if item_type is None:
|
||||||
item_type = project_type
|
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 item['parent_id'] == 0:
|
||||||
if project_type == 'serial':
|
if project_type == 'serial':
|
||||||
if not first_found:
|
if not first_found:
|
||||||
|
@ -193,6 +200,7 @@ def main():
|
||||||
elif project_type == 'parallel':
|
elif project_type == 'parallel':
|
||||||
add_label(item, label_id)
|
add_label(item, label_id)
|
||||||
else:
|
else:
|
||||||
|
# If only the item type has been defined
|
||||||
if item_type:
|
if item_type:
|
||||||
add_label(item, label_id)
|
add_label(item, label_id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue