mirror of https://github.com/Hoffelhas/autodoist
Changed end-of-day functionality, but apparently updating the due-date with the new API will remove the recurring settings. Brilliant. Need to find a fix for this.
parent
4aad462ce3
commit
24d88460fb
139
autodoist.py
139
autodoist.py
|
@ -150,10 +150,10 @@ def db_check_existance(connection, model):
|
||||||
if isinstance(model, Task):
|
if isinstance(model, Task):
|
||||||
q_create = """
|
q_create = """
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
tasks (task_id, task_type, parent_type, r_tag)
|
tasks (task_id, task_type, parent_type, due_date, r_tag)
|
||||||
VALUES
|
VALUES
|
||||||
(%r, %s, %s, %i);
|
(%r, %s, %s, %s, %i);
|
||||||
""" % (model.id, 'NULL', 'NULL', 0)
|
""" % (model.id, 'NULL', 'NULL', 'NULL', 0)
|
||||||
|
|
||||||
if isinstance(model, Section):
|
if isinstance(model, Section):
|
||||||
q_create = """
|
q_create = """
|
||||||
|
@ -208,6 +208,7 @@ def initialise_sqlite():
|
||||||
task_id INTEGER,
|
task_id INTEGER,
|
||||||
task_type TEXT,
|
task_type TEXT,
|
||||||
parent_type TEXT,
|
parent_type TEXT,
|
||||||
|
due_date TEXT,
|
||||||
r_tag INTEGER
|
r_tag INTEGER
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
|
@ -506,7 +507,7 @@ def get_type(args, connection, model, key):
|
||||||
elif isinstance(model, Project):
|
elif isinstance(model, Project):
|
||||||
current_type = check_name(args, model.name, 3) # Projects
|
current_type = check_name(args, model.name, 3) # Projects
|
||||||
|
|
||||||
# Check if project type changed with respect to previous run
|
# Check if type changed with respect to previous run
|
||||||
if old_type == current_type:
|
if old_type == current_type:
|
||||||
type_changed = 0
|
type_changed = 0
|
||||||
else:
|
else:
|
||||||
|
@ -687,43 +688,52 @@ def check_regen_mode(api, item, regen_labels_id):
|
||||||
# Recurring lists logic
|
# Recurring lists logic
|
||||||
|
|
||||||
|
|
||||||
def run_recurring_lists_logic(args, api, item, child_items, child_items_all, regen_labels_id):
|
def run_recurring_lists_logic(args, api,connection, task, task_items, task_items_all, regen_labels_id):
|
||||||
|
|
||||||
if item['parent_id'] == 0:
|
if task.parent_id == 0:
|
||||||
try:
|
try:
|
||||||
if item['due']['is_recurring']:
|
if task.due.is_recurring:
|
||||||
try:
|
try:
|
||||||
# Check if the T0 task date has changed
|
db_task_due_date = db_read_value(connection, task, 'due_date')[0][0]
|
||||||
if item['due']['date'][:10] != item['date_old']:
|
|
||||||
|
|
||||||
# Mark children for action based on mode
|
if db_task_due_date is None:
|
||||||
if args.regeneration is not None:
|
# If date has never been saved before, create a new entry
|
||||||
|
logging.debug(
|
||||||
|
'New recurring task detected: %s' % task.content)
|
||||||
|
db_update_value(connection, task, 'due_date', task.due.date)
|
||||||
|
|
||||||
# Check if task has a regen label
|
# Check if the T0 task date has changed, because a user has checked the task
|
||||||
regen_mode = check_regen_mode(
|
if task.due.date != db_task_due_date:
|
||||||
api, item, regen_labels_id)
|
|
||||||
|
|
||||||
# If no label, use general mode instead
|
#TODO: reevaluate regeneration mode. Disabled for now.
|
||||||
if regen_mode is None:
|
# # Mark children for action based on mode
|
||||||
regen_mode = args.regeneration
|
# if args.regeneration is not None:
|
||||||
logging.debug('Using general recurring mode \'%s\' for item: %s',
|
|
||||||
regen_mode, item.content)
|
|
||||||
else:
|
|
||||||
logging.debug('Using recurring label \'%s\' for item: %s',
|
|
||||||
regen_mode, item.content)
|
|
||||||
|
|
||||||
# Apply tags based on mode
|
# # Check if task has a regen label
|
||||||
give_regen_tag = 0
|
# regen_mode = check_regen_mode(
|
||||||
|
# api, item, regen_labels_id)
|
||||||
|
|
||||||
if regen_mode == 1: # Regen all
|
# # If no label, use general mode instead
|
||||||
give_regen_tag = 1
|
# if regen_mode is None:
|
||||||
elif regen_mode == 2: # Regen if all sub-tasks completed
|
# regen_mode = args.regeneration
|
||||||
if not child_items:
|
# logging.debug('Using general recurring mode \'%s\' for item: %s',
|
||||||
give_regen_tag = 1
|
# regen_mode, item.content)
|
||||||
|
# else:
|
||||||
|
# logging.debug('Using recurring label \'%s\' for item: %s',
|
||||||
|
# regen_mode, item.content)
|
||||||
|
|
||||||
if give_regen_tag == 1:
|
# # Apply tags based on mode
|
||||||
for child_item in child_items_all:
|
# give_regen_tag = 0
|
||||||
child_item['r_tag'] = 1
|
|
||||||
|
# if regen_mode == 1: # Regen all
|
||||||
|
# give_regen_tag = 1
|
||||||
|
# elif regen_mode == 2: # Regen if all sub-tasks completed
|
||||||
|
# if not child_items:
|
||||||
|
# give_regen_tag = 1
|
||||||
|
|
||||||
|
# if give_regen_tag == 1:
|
||||||
|
# for child_item in child_items_all:
|
||||||
|
# child_item['r_tag'] = 1
|
||||||
|
|
||||||
# If alternative end of day, fix due date if needed
|
# If alternative end of day, fix due date if needed
|
||||||
if args.end is not None:
|
if args.end is not None:
|
||||||
|
@ -735,10 +745,8 @@ def run_recurring_lists_logic(args, api, item, child_items, child_items_all, reg
|
||||||
if (args.end - current_hour) > 0:
|
if (args.end - current_hour) > 0:
|
||||||
|
|
||||||
# Determine the difference in days set by todoist
|
# Determine the difference in days set by todoist
|
||||||
nd = [
|
nd = [int(x) for x in task.due.date.split('-')]
|
||||||
int(x) for x in item['due']['date'][:10].split('-')]
|
od = [int(x) for x in db_task_due_date.split('-')]
|
||||||
od = [
|
|
||||||
int(x) for x in item['date_old'][:10].split('-')]
|
|
||||||
|
|
||||||
new_date = datetime(
|
new_date = datetime(
|
||||||
nd[0], nd[1], nd[2])
|
nd[0], nd[1], nd[2])
|
||||||
|
@ -755,49 +763,38 @@ def run_recurring_lists_logic(args, api, item, child_items, child_items_all, reg
|
||||||
if days_overdue >= 1 and days_difference == 1:
|
if days_overdue >= 1 and days_difference == 1:
|
||||||
|
|
||||||
# Find current date in string format
|
# Find current date in string format
|
||||||
today_str = [str(x) for x in [
|
today_str = t.strftime("%Y-%m-%d")
|
||||||
today.year, today.month, today.day]]
|
|
||||||
if len(today_str[1]) == 1:
|
|
||||||
today_str[1] = ''.join(
|
|
||||||
['0', today_str[1]])
|
|
||||||
|
|
||||||
# Update due-date to today
|
# Update due-date to today
|
||||||
item_due = item['due']
|
api.update_task(task_id=task.id, due_date=today_str) #TODO: Apparently this breaks the reccuring string...
|
||||||
item_due['date'] = '-'.join(
|
|
||||||
today_str)
|
|
||||||
item.update(due=item_due)
|
|
||||||
# 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(
|
db_update_value(connection, task, 'due_date', task.due.date)
|
||||||
date_old=item['due']['date'][:10])
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# 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' % item.content)
|
'New recurring task detected: %s' % task.content)
|
||||||
item['date_old'] = item['due']['date'][:10]
|
db_update_value(connection, task, 'due_date', task.due.date)
|
||||||
api.items.update(item['id'])
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# logging.debug(
|
|
||||||
# 'Parent not recurring: %s' % item.content)
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
#TODO: reevaluate regeneration mode. Disabled for now.
|
||||||
|
# if args.regeneration is not None and item.parent_id != 0:
|
||||||
|
# try:
|
||||||
|
# if item['r_tag'] == 1:
|
||||||
|
# item.update(checked=0)
|
||||||
|
# item.update(in_history=0)
|
||||||
|
# item['r_tag'] = 0
|
||||||
|
# api.items.update(item['id'])
|
||||||
|
|
||||||
if args.regeneration is not None and item['parent_id'] != 0:
|
# for child_item in child_items_all:
|
||||||
try:
|
# child_item['r_tag'] = 1
|
||||||
if item['r_tag'] == 1:
|
# except:
|
||||||
item.update(checked=0)
|
# # logging.debug('Child not recurring: %s' %
|
||||||
item.update(in_history=0)
|
# # item.content)
|
||||||
item['r_tag'] = 0
|
# pass
|
||||||
api.items.update(item['id'])
|
|
||||||
|
|
||||||
for child_item in child_items_all:
|
|
||||||
child_item['r_tag'] = 1
|
|
||||||
except:
|
|
||||||
# logging.debug('Child not recurring: %s' %
|
|
||||||
# item.content)
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Find and clean all children under a task
|
# Find and clean all children under a task
|
||||||
|
|
||||||
|
@ -968,10 +965,10 @@ def autodoist_magic(args, api, connection):
|
||||||
# except:
|
# except:
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
# # If options turned on, start recurring lists logic
|
# If options turned on, start recurring lists logic #TODO: regeneration currently doesn't work, becaue TASK_ENDPOINT doesn't show completed tasks. Use workaround.
|
||||||
# if args.regeneration is not None or args.end:
|
if args.regeneration is not None or args.end:
|
||||||
# run_recurring_lists_logic(
|
run_recurring_lists_logic(
|
||||||
# args, api, item, child_items, child_items_all, regen_labels_id)
|
args, api, connection, task, child_tasks, child_tasks_all, regen_labels_id)
|
||||||
|
|
||||||
# If options turned on, start labelling logic
|
# If options turned on, start labelling logic
|
||||||
if next_action_label is not None:
|
if next_action_label is not None:
|
||||||
|
|
Loading…
Reference in New Issue