mirror of https://github.com/Hoffelhas/autodoist
Bug has magically gone away on Todoist's end. For now moving on.
Parser lay-out, help content, and arguments have been improved.pull/15/head
parent
c4792b9a17
commit
a552954d8b
105
autodoist.py
105
autodoist.py
|
@ -11,34 +11,51 @@ from datetime import datetime
|
||||||
global overview_item_ids
|
global overview_item_ids
|
||||||
global overview_item_labels
|
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():
|
def main():
|
||||||
|
|
||||||
# Version
|
# Version
|
||||||
current_version = 'v1.2'
|
current_version = 'v1.2'
|
||||||
|
|
||||||
"""Main process function."""
|
"""Main process function."""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser(
|
||||||
parser.add_argument('-a', '--api_key', help='Todoist API Key')
|
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(
|
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(
|
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(
|
parser.add_argument(
|
||||||
'-r', '--recurring', help='Enable re-use of recurring lists', action='store_true')
|
'-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('--debug', help='Enable debugging',
|
parser.add_argument(
|
||||||
action='store_true')
|
'-d', '--delay', help='Specify the delay in seconds between syncs (default 5).', default=5, type=int)
|
||||||
parser.add_argument('--inbox', help='The method the Inbox project should be processed',
|
parser.add_argument(
|
||||||
default=None, choices=['parallel', 'sequential'])
|
'-ps', '--p_suffix', help='Change suffix for parallel labeling (default "//").', default='//')
|
||||||
parser.add_argument('--parallel_suffix', default='//')
|
parser.add_argument(
|
||||||
parser.add_argument('--sequential_suffix', default='--')
|
'-ss', '--s_suffix', help='Change suffix for sequential labeling (default "--").', default='--')
|
||||||
parser.add_argument('--hide_future', help='Hide future dated next actions until the specified number of days',
|
parser.add_argument('-hf', '--hide_future', help='Hide future dated next actions until the specified number of days (default 7).',
|
||||||
default=7, type=int)
|
default=7, type=int)
|
||||||
parser.add_argument(
|
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(
|
parser.add_argument(
|
||||||
'--nocache', help='Disables caching data to disk for quicker syncing', action='store_true')
|
'--nocache', help='Disables caching data to disk for quicker syncing.', action='store_true')
|
||||||
parser.add_argument(
|
parser.add_argument('--debug', help='Enable detailed debugging in log.',
|
||||||
'-e', '--end', help='Enter a number from 1-24 to define which hour is used as end-of-day time.', type=int)
|
action='store_true')
|
||||||
|
parser.add_argument('--inbox', help='The method the Inbox should be processed.',
|
||||||
|
default=None, choices=['parallel', 'sequential'])
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Set debug
|
# Set debug
|
||||||
|
@ -59,13 +76,15 @@ def main():
|
||||||
|
|
||||||
# Check we have a API key
|
# Check we have a API key
|
||||||
if not args.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)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check if AEOD is used
|
# Check if AEOD is used
|
||||||
if args.end is not None:
|
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 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)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
@ -95,7 +114,7 @@ def main():
|
||||||
if len(labels) > 0:
|
if len(labels) > 0:
|
||||||
label_id = labels[0]['id']
|
label_id = labels[0]['id']
|
||||||
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
|
# Create a new label in Todoist
|
||||||
#TODO:
|
#TODO:
|
||||||
|
@ -137,7 +156,7 @@ def main():
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def get_type(object, key):
|
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:
|
try:
|
||||||
old_type = object[key]
|
old_type = object[key]
|
||||||
|
@ -152,9 +171,9 @@ def main():
|
||||||
|
|
||||||
if name == 'Inbox':
|
if name == 'Inbox':
|
||||||
current_type = args.inbox
|
current_type = args.inbox
|
||||||
elif name[-len_suffix[0]:] == args.parallel_suffix:
|
elif name[-len_suffix[0]:] == args.p_suffix:
|
||||||
current_type = 'parallel'
|
current_type = 'parallel'
|
||||||
elif name[-len_suffix[1]:] == args.sequential_suffix:
|
elif name[-len_suffix[1]:] == args.s_suffix:
|
||||||
current_type = 'sequential'
|
current_type = 'sequential'
|
||||||
else:
|
else:
|
||||||
current_type = None
|
current_type = None
|
||||||
|
@ -238,7 +257,7 @@ def main():
|
||||||
# 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',
|
||||||
project['name'], project_type)
|
project['name'], project_type)
|
||||||
|
|
||||||
# Get all items for the project
|
# Get all items for the project
|
||||||
items = api.items.all(
|
items = api.items.all(
|
||||||
|
@ -295,8 +314,6 @@ def main():
|
||||||
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['date_old']:
|
if item['due']['date'] != item['date_old']:
|
||||||
|
|
||||||
|
@ -309,31 +326,42 @@ def main():
|
||||||
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 = [int(x) for x in item['due']['date'].split('-')]
|
nd = [
|
||||||
od = [int(x) for x in item['old_date'].split('-')]
|
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])
|
new_date = datetime(
|
||||||
old_date = datetime(od[0], od[1], od[2])
|
nd[0], nd[1], nd[2])
|
||||||
today = datetime(t.year, t.month, t.day)
|
old_date = datetime(
|
||||||
days_difference = (new_date-today).days
|
od[0], od[1], od[2])
|
||||||
days_overdue = (today - old_date).days
|
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
|
# Only apply if overdue and if it's a daily recurring tasks
|
||||||
if days_overdue >= 1 and days_difference == 1:
|
if days_overdue >= 1 and days_difference == 1:
|
||||||
|
|
||||||
# Find curreny date in string format
|
# 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:
|
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
|
# Update due-date to today
|
||||||
item_due = item['due']
|
item_due = item['due']
|
||||||
item_due['date'] = '-'.join(today_str)
|
item_due['date'] = '-'.join(
|
||||||
|
today_str)
|
||||||
item.update(due=item_due)
|
item.update(due=item_due)
|
||||||
# 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(date_old=item['due']['date'])
|
item.update(
|
||||||
|
date_old=item['due']['date'])
|
||||||
|
|
||||||
# Mark children for action
|
# Mark children for action
|
||||||
if args.recurring is True:
|
if args.recurring is True:
|
||||||
|
@ -363,7 +391,8 @@ 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' % item['content'])
|
logging.debug('Child not recurring: %s' %
|
||||||
|
item['content'])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# If options turned on, start labelling logic
|
# If options turned on, start labelling logic
|
||||||
|
@ -376,7 +405,7 @@ def main():
|
||||||
item_type, item_type_changed = get_item_type(
|
item_type, item_type_changed = get_item_type(
|
||||||
item, project_type)
|
item, project_type)
|
||||||
logging.debug('Identified \'%s\' as %s type',
|
logging.debug('Identified \'%s\' as %s type',
|
||||||
item['content'], item_type)
|
item['content'], item_type)
|
||||||
|
|
||||||
# Check the item_type of the project or parent
|
# Check the item_type of the project or parent
|
||||||
if item_type is None:
|
if item_type is None:
|
||||||
|
|
Loading…
Reference in New Issue