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.

pull/30/head
Hoffelhas 2023-01-08 22:23:54 +01:00
parent 4aad462ce3
commit 24d88460fb
1 changed files with 68 additions and 71 deletions

View File

@ -150,10 +150,10 @@ def db_check_existance(connection, model):
if isinstance(model, Task):
q_create = """
INSERT INTO
tasks (task_id, task_type, parent_type, r_tag)
tasks (task_id, task_type, parent_type, due_date, r_tag)
VALUES
(%r, %s, %s, %i);
""" % (model.id, 'NULL', 'NULL', 0)
(%r, %s, %s, %s, %i);
""" % (model.id, 'NULL', 'NULL', 'NULL', 0)
if isinstance(model, Section):
q_create = """
@ -208,6 +208,7 @@ def initialise_sqlite():
task_id INTEGER,
task_type TEXT,
parent_type TEXT,
due_date TEXT,
r_tag INTEGER
);
"""
@ -506,7 +507,7 @@ def get_type(args, connection, model, key):
elif isinstance(model, Project):
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:
type_changed = 0
else:
@ -687,43 +688,52 @@ def check_regen_mode(api, item, regen_labels_id):
# 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:
if item['due']['is_recurring']:
if task.due.is_recurring:
try:
# Check if the T0 task date has changed
if item['due']['date'][:10] != item['date_old']:
db_task_due_date = db_read_value(connection, task, 'due_date')[0][0]
# Mark children for action based on mode
if args.regeneration is not None:
if db_task_due_date is 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
regen_mode = check_regen_mode(
api, item, regen_labels_id)
# Check if the T0 task date has changed, because a user has checked the task
if task.due.date != db_task_due_date:
# If no label, use general mode instead
if regen_mode is None:
regen_mode = args.regeneration
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)
#TODO: reevaluate regeneration mode. Disabled for now.
# # Mark children for action based on mode
# if args.regeneration is not None:
# Apply tags based on mode
give_regen_tag = 0
# # Check if task has a regen label
# regen_mode = check_regen_mode(
# api, item, regen_labels_id)
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 no label, use general mode instead
# if regen_mode is None:
# regen_mode = args.regeneration
# 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)
if give_regen_tag == 1:
for child_item in child_items_all:
child_item['r_tag'] = 1
# # Apply tags based on mode
# give_regen_tag = 0
# 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 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:
# Determine the difference in days set by todoist
nd = [
int(x) for x in item['due']['date'][:10].split('-')]
od = [
int(x) for x in item['date_old'][:10].split('-')]
nd = [int(x) for x in task.due.date.split('-')]
od = [int(x) for x in db_task_due_date.split('-')]
new_date = datetime(
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:
# Find current date in string format
today_str = [str(x) for x in [
today.year, today.month, today.day]]
if len(today_str[1]) == 1:
today_str[1] = ''.join(
['0', today_str[1]])
today_str = t.strftime("%Y-%m-%d")
# Update due-date to today
item_due = item['due']
item_due['date'] = '-'.join(
today_str)
item.update(due=item_due)
# item.update(due={'date': '2020-05-29', 'is_recurring': True, 'string': 'every day'})
api.update_task(task_id=task.id, due_date=today_str) #TODO: Apparently this breaks the reccuring string...
# Save the new date for reference us
item.update(
date_old=item['due']['date'][:10])
db_update_value(connection, task, 'due_date', task.due.date)
except:
# If date has never been saved before, create a new entry
logging.debug(
'New recurring task detected: %s' % item.content)
item['date_old'] = item['due']['date'][:10]
api.items.update(item['id'])
'New recurring task detected: %s' % task.content)
db_update_value(connection, task, 'due_date', task.due.date)
except:
# logging.debug(
# 'Parent not recurring: %s' % item.content)
pass
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'])
#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'])
for child_item in child_items_all:
child_item['r_tag'] = 1
except:
# logging.debug('Child not recurring: %s' %
# item.content)
pass
# 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
@ -968,10 +965,10 @@ def autodoist_magic(args, api, connection):
# except:
# pass
# # If options turned on, start recurring lists logic
# if args.regeneration is not None or args.end:
# run_recurring_lists_logic(
# args, api, item, child_items, child_items_all, regen_labels_id)
# 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:
run_recurring_lists_logic(
args, api, connection, task, child_tasks, child_tasks_all, regen_labels_id)
# If options turned on, start labelling logic
if next_action_label is not None: