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
Hoffelhas 2020-05-30 12:29:25 +02:00
parent 4690b68245
commit c4792b9a17
1 changed files with 171 additions and 151 deletions

View File

@ -20,7 +20,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--api_key', help='Todoist API Key')
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(
'-d', '--delay', help='Specify the delay in seconds between syncs', default=5, type=int)
parser.add_argument(
@ -62,9 +62,13 @@ def main():
logging.error("\n\nNo API key set. Run Autodoist with '-a <YOUR_API_KEY>'\n")
sys.exit(1)
# Check if AEOD is used
if args.end is not None:
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)
else:
pass
# Run the initial sync
logging.debug('Connecting to the Todoist API')
@ -75,9 +79,17 @@ def main():
api_arguments['cache'] = None
api = TodoistAPI(**api_arguments)
try:
logging.debug('Syncing the current state from the API')
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
labels = api.labels.all(lambda x: x['name'] == args.label)
if len(labels) > 0:
@ -85,9 +97,14 @@ def main():
logging.debug('Label \'%s\' found as label id %d',
args.label, label_id)
else:
# Create a new label in Todoist
#TODO:
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)
sys.exit(1)
else:
# Label functionality not needed
label_id = None
logging.info("\nAutodoist has connected and is running fine!\n")
@ -215,15 +232,9 @@ def main():
overview_item_ids = {}
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():
if label_id is not None:
# Get project type
project_type, project_type_changed = get_project_type(project)
logging.debug('Project \'%s\' being processed as %s',
@ -244,6 +255,7 @@ def main():
items = list(
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_changed == 1:
# Remove labels
@ -276,15 +288,19 @@ def main():
api.items.update(item['id'])
except Exception as e:
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:
try:
if item['due']['is_recurring']:
try:
if item['content'] == 'TASK':
print('b;ah')
# 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
t = datetime.today()
current_hour = t.hour
@ -317,25 +333,26 @@ def main():
# item.update(due={'date': '2020-05-29', 'is_recurring': True, 'string': 'every day'})
# 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
if args.recurring is True:
for child_item in child_items_all:
child_item['r_tag'] = 1
except Exception as e:
# If date has never been saved before, create a new entry
logging.debug(
'New recurring task detected: %s' % str(e))
item['old_date'] = item['due']['date']
'New recurring task detected: %s' % item['content'])
item['date_old'] = item['due']['date']
api.items.update(item['id'])
except Exception as e:
logging.debug(
'Parent not recurring: %s' % str(e))
'Parent not recurring: %s' % item['content'])
pass
if item['parent_id'] != 0:
if args.recurring is True and item['parent_id'] != 0:
try:
if item['r_tag'] == 1:
item.update(checked=0)
@ -346,9 +363,11 @@ def main():
for child_item in child_items_all:
child_item['r_tag'] = 1
except Exception as e:
logging.debug('Child not recurring: %s' % str(e))
logging.debug('Child not recurring: %s' % item['content'])
pass
# If options turned on, start labelling logic
if label_id is not None:
# Skip processing an item if it has already been checked
if item['checked'] == 1:
continue
@ -433,6 +452,7 @@ def main():
continue
# Commit the queue with changes
if label_id is not None:
update_labels(label_id)
if len(api.queue):