Bug has magically gone away on Todoist's end. For now moving on.

Parser lay-out, help content, and arguments have been improved.
master
Hoffelhas 2020-05-30 13:14:07 +02:00
parent c4792b9a17
commit a552954d8b
1 changed files with 78 additions and 49 deletions

View File

@ -11,34 +11,51 @@ from datetime import datetime
global overview_item_ids
global overview_item_labels
def make_wide(formatter, w=120, h=36):
"""Return a wider HelpFormatter, if possible."""
try:
# https://stackoverflow.com/a/5464440
# beware: "Only the name of this class is considered a public API."
kwargs = {'width': w, 'max_help_position': h}
formatter(None, **kwargs)
return lambda prog: formatter(prog, **kwargs)
except TypeError:
warnings.warn("argparse help formatter failed, falling back.")
return formatter
def main():
# Version
current_version = 'v1.2'
"""Main process function."""
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--api_key', help='Todoist API Key')
parser = argparse.ArgumentParser(
formatter_class=make_wide(argparse.HelpFormatter, w=110, h=50))
parser.add_argument('-a', '--api_key', help='Takes your Todoist API Key.', type=str)
parser.add_argument(
'-l', '--label', help='The next action label to use', type=str)
'-l', '--label', help='Enable next action labelling. Define which label to use.', type=str)
parser.add_argument(
'-d', '--delay', help='Specify the delay in seconds between syncs', default=5, type=int)
'-r', '--recurring', help='Enable regeneration of sub-tasks in recurring lists.', action='store_true')
parser.add_argument(
'-r', '--recurring', help='Enable re-use of recurring lists', action='store_true')
parser.add_argument('--debug', help='Enable debugging',
action='store_true')
parser.add_argument('--inbox', help='The method the Inbox project should be processed',
default=None, choices=['parallel', 'sequential'])
parser.add_argument('--parallel_suffix', default='//')
parser.add_argument('--sequential_suffix', default='--')
parser.add_argument('--hide_future', help='Hide future dated next actions until the specified number of days',
'-e', '--end', help='Enable alternative end-of-day time instead of default midnight. Enter a number from 1 to 24 to define which hour is used.', type=int)
parser.add_argument(
'-d', '--delay', help='Specify the delay in seconds between syncs (default 5).', default=5, type=int)
parser.add_argument(
'-ps', '--p_suffix', help='Change suffix for parallel labeling (default "//").', default='//')
parser.add_argument(
'-ss', '--s_suffix', help='Change suffix for sequential labeling (default "--").', default='--')
parser.add_argument('-hf', '--hide_future', help='Hide future dated next actions until the specified number of days (default 7).',
default=7, type=int)
parser.add_argument(
'--onetime', help='Update Todoist once and exit', action='store_true')
'--onetime', help='Update Todoist once and exit.', action='store_true')
parser.add_argument(
'--nocache', help='Disables caching data to disk for quicker syncing', action='store_true')
parser.add_argument(
'-e', '--end', help='Enter a number from 1-24 to define which hour is used as end-of-day time.', type=int)
'--nocache', help='Disables caching data to disk for quicker syncing.', action='store_true')
parser.add_argument('--debug', help='Enable detailed debugging in log.',
action='store_true')
parser.add_argument('--inbox', help='The method the Inbox should be processed.',
default=None, choices=['parallel', 'sequential'])
args = parser.parse_args()
# Set debug
@ -59,13 +76,15 @@ def main():
# Check we have a API key
if not args.api_key:
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)
# 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 1 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
@ -137,7 +156,7 @@ def main():
return 1
def get_type(object, key):
len_suffix = [len(args.parallel_suffix), len(args.sequential_suffix)]
len_suffix = [len(args.p_suffix), len(args.s_suffix)]
try:
old_type = object[key]
@ -152,9 +171,9 @@ def main():
if name == 'Inbox':
current_type = args.inbox
elif name[-len_suffix[0]:] == args.parallel_suffix:
elif name[-len_suffix[0]:] == args.p_suffix:
current_type = 'parallel'
elif name[-len_suffix[1]:] == args.sequential_suffix:
elif name[-len_suffix[1]:] == args.s_suffix:
current_type = 'sequential'
else:
current_type = None
@ -295,8 +314,6 @@ def main():
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['date_old']:
@ -309,31 +326,42 @@ def main():
if (args.end - current_hour) > 0:
# Determine the difference in days set by todoist
nd = [int(x) for x in item['due']['date'].split('-')]
od = [int(x) for x in item['old_date'].split('-')]
nd = [
int(x) for x in item['due']['date'].split('-')]
od = [
int(x) for x in item['date_old'].split('-')]
new_date = datetime(nd[0], nd[1], nd[2])
old_date = datetime(od[0], od[1], od[2])
today = datetime(t.year, t.month, t.day)
days_difference = (new_date-today).days
days_overdue = (today - old_date).days
new_date = datetime(
nd[0], nd[1], nd[2])
old_date = datetime(
od[0], od[1], od[2])
today = datetime(
t.year, t.month, t.day)
days_difference = (
new_date-today).days
days_overdue = (
today - old_date).days
# Only apply if overdue and if it's a daily recurring tasks
if days_overdue >= 1 and days_difference == 1:
# Find curreny date in string format
today_str = [str(x) for x in [today.year, today.month, today.day]]
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[1] = ''.join(
['0', today_str[1]])
# Update due-date to today
item_due = item['due']
item_due['date'] = '-'.join(today_str)
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
item.update(date_old=item['due']['date'])
item.update(
date_old=item['due']['date'])
# Mark children for action
if args.recurring is True:
@ -363,7 +391,8 @@ def main():
for child_item in child_items_all:
child_item['r_tag'] = 1
except Exception as e:
logging.debug('Child not recurring: %s' % item['content'])
logging.debug('Child not recurring: %s' %
item['content'])
pass
# If options turned on, start labelling logic