forked from mirrors/autodoist
Strange bug found when testing the modulised lay-out.
Tasks that have been given an old_date show unexplained behaviour. If set on today and recurring every day, checking it will move it TWO days.master
parent
4690b68245
commit
c4792b9a17
56
autodoist.py
56
autodoist.py
|
@ -20,7 +20,7 @@ def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-a', '--api_key', help='Todoist API Key')
|
parser.add_argument('-a', '--api_key', help='Todoist API Key')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-l', '--label', help='The next action label to use', default='next_action')
|
'-l', '--label', help='The next action label to use', type=str)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--delay', help='Specify the delay in seconds between syncs', default=5, type=int)
|
'-d', '--delay', help='Specify the delay in seconds between syncs', default=5, type=int)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -62,9 +62,13 @@ def main():
|
||||||
logging.error("\n\nNo API key set. Run Autodoist with '-a <YOUR_API_KEY>'\n")
|
logging.error("\n\nNo API key set. Run Autodoist with '-a <YOUR_API_KEY>'\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Check if AEOD is used
|
||||||
|
if args.end is not None:
|
||||||
if args.end < 1 or args.end > 24:
|
if args.end < 1 or args.end > 24:
|
||||||
logging.error("\n\nPlease choose a number from 0 to 24 to indicate which hour is used as alternative end-of-day time.\n")
|
logging.error("\n\nPlease choose a number from 1 to 24 to indicate which hour is used as alternative end-of-day time.\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
# Run the initial sync
|
# Run the initial sync
|
||||||
logging.debug('Connecting to the Todoist API')
|
logging.debug('Connecting to the Todoist API')
|
||||||
|
@ -75,9 +79,17 @@ def main():
|
||||||
api_arguments['cache'] = None
|
api_arguments['cache'] = None
|
||||||
|
|
||||||
api = TodoistAPI(**api_arguments)
|
api = TodoistAPI(**api_arguments)
|
||||||
|
|
||||||
|
try:
|
||||||
logging.debug('Syncing the current state from the API')
|
logging.debug('Syncing the current state from the API')
|
||||||
api.sync()
|
api.sync()
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception(
|
||||||
|
'Error trying to sync with Todoist API: %s' % str(e))
|
||||||
|
quit()
|
||||||
|
|
||||||
|
# Check if label argument is used
|
||||||
|
if args.label is not None:
|
||||||
# Check the next action label exists
|
# Check the next action label exists
|
||||||
labels = api.labels.all(lambda x: x['name'] == args.label)
|
labels = api.labels.all(lambda x: x['name'] == args.label)
|
||||||
if len(labels) > 0:
|
if len(labels) > 0:
|
||||||
|
@ -85,9 +97,14 @@ def main():
|
||||||
logging.debug('Label \'%s\' found as label id %d',
|
logging.debug('Label \'%s\' found as label id %d',
|
||||||
args.label, label_id)
|
args.label, label_id)
|
||||||
else:
|
else:
|
||||||
|
# Create a new label in Todoist
|
||||||
|
#TODO:
|
||||||
logging.error(
|
logging.error(
|
||||||
"\n\nLabel \'%s\' doesn't exist in your Todoist. Please create it or use your custom label by running Autodoist with the argument '-l <YOUR_EXACT_LABEL>'.\n", args.label)
|
"\n\nLabel \'%s\' doesn't exist in your Todoist. Please create it or use your custom label by running Autodoist with the argument '-l <YOUR_EXACT_LABEL>'.\n", args.label)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
# Label functionality not needed
|
||||||
|
label_id = None
|
||||||
|
|
||||||
logging.info("\nAutodoist has connected and is running fine!\n")
|
logging.info("\nAutodoist has connected and is running fine!\n")
|
||||||
|
|
||||||
|
@ -215,15 +232,9 @@ def main():
|
||||||
overview_item_ids = {}
|
overview_item_ids = {}
|
||||||
overview_item_labels = {}
|
overview_item_labels = {}
|
||||||
|
|
||||||
try:
|
|
||||||
api.sync()
|
|
||||||
except Exception as e:
|
|
||||||
logging.exception(
|
|
||||||
'Error trying to sync with Todoist API: %s' % str(e))
|
|
||||||
quit()
|
|
||||||
|
|
||||||
for project in api.projects.all():
|
for project in api.projects.all():
|
||||||
|
|
||||||
|
if label_id is not None:
|
||||||
# Get project type
|
# Get project type
|
||||||
project_type, project_type_changed = get_project_type(project)
|
project_type, project_type_changed = get_project_type(project)
|
||||||
logging.debug('Project \'%s\' being processed as %s',
|
logging.debug('Project \'%s\' being processed as %s',
|
||||||
|
@ -244,6 +255,7 @@ def main():
|
||||||
items = list(
|
items = list(
|
||||||
filter(lambda x: not x['content'].startswith('*'), items))
|
filter(lambda x: not x['content'].startswith('*'), items))
|
||||||
|
|
||||||
|
if label_id is not None:
|
||||||
# If project type has been changed, clean everything for good measure
|
# If project type has been changed, clean everything for good measure
|
||||||
if project_type_changed == 1:
|
if project_type_changed == 1:
|
||||||
# Remove labels
|
# Remove labels
|
||||||
|
@ -276,15 +288,19 @@ def main():
|
||||||
api.items.update(item['id'])
|
api.items.update(item['id'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
# If option turned on, start recurring logic
|
|
||||||
else:
|
# If options turned on, start recurring lists logic
|
||||||
|
if args.recurring or args.end:
|
||||||
if item['parent_id'] == 0:
|
if item['parent_id'] == 0:
|
||||||
try:
|
try:
|
||||||
if item['due']['is_recurring']:
|
if item['due']['is_recurring']:
|
||||||
try:
|
try:
|
||||||
|
if item['content'] == 'TASK':
|
||||||
|
print('b;ah')
|
||||||
# Check if the T0 task date has changed
|
# Check if the T0 task date has changed
|
||||||
if item['due']['date'] != item['old_date']:
|
if item['due']['date'] != item['date_old']:
|
||||||
|
|
||||||
|
if args.end is not None:
|
||||||
# Determine current hour
|
# Determine current hour
|
||||||
t = datetime.today()
|
t = datetime.today()
|
||||||
current_hour = t.hour
|
current_hour = t.hour
|
||||||
|
@ -317,25 +333,26 @@ def main():
|
||||||
# item.update(due={'date': '2020-05-29', 'is_recurring': True, 'string': 'every day'})
|
# item.update(due={'date': '2020-05-29', 'is_recurring': True, 'string': 'every day'})
|
||||||
|
|
||||||
# Save the new date for reference us
|
# Save the new date for reference us
|
||||||
item.update(old_date=item['due']['date'])
|
item.update(date_old=item['due']['date'])
|
||||||
|
|
||||||
# Mark children for action
|
# Mark children for action
|
||||||
|
if args.recurring is True:
|
||||||
for child_item in child_items_all:
|
for child_item in child_items_all:
|
||||||
child_item['r_tag'] = 1
|
child_item['r_tag'] = 1
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# If date has never been saved before, create a new entry
|
# If date has never been saved before, create a new entry
|
||||||
logging.debug(
|
logging.debug(
|
||||||
'New recurring task detected: %s' % str(e))
|
'New recurring task detected: %s' % item['content'])
|
||||||
item['old_date'] = item['due']['date']
|
item['date_old'] = item['due']['date']
|
||||||
api.items.update(item['id'])
|
api.items.update(item['id'])
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
'Parent not recurring: %s' % str(e))
|
'Parent not recurring: %s' % item['content'])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if item['parent_id'] != 0:
|
if args.recurring is True and item['parent_id'] != 0:
|
||||||
try:
|
try:
|
||||||
if item['r_tag'] == 1:
|
if item['r_tag'] == 1:
|
||||||
item.update(checked=0)
|
item.update(checked=0)
|
||||||
|
@ -346,9 +363,11 @@ def main():
|
||||||
for child_item in child_items_all:
|
for child_item in child_items_all:
|
||||||
child_item['r_tag'] = 1
|
child_item['r_tag'] = 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.debug('Child not recurring: %s' % str(e))
|
logging.debug('Child not recurring: %s' % item['content'])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# If options turned on, start labelling logic
|
||||||
|
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
|
||||||
if item['checked'] == 1:
|
if item['checked'] == 1:
|
||||||
continue
|
continue
|
||||||
|
@ -433,6 +452,7 @@ def main():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Commit the queue with changes
|
# Commit the queue with changes
|
||||||
|
if label_id is not None:
|
||||||
update_labels(label_id)
|
update_labels(label_id)
|
||||||
|
|
||||||
if len(api.queue):
|
if len(api.queue):
|
||||||
|
|
Loading…
Reference in New Issue