1) Hide-future date has been fixed 2) start-date functionality added

master
Hoffelhas 2020-06-13 15:26:56 +02:00
parent 82b8bd2385
commit 9645942c5c
1 changed files with 41 additions and 17 deletions

View File

@ -1,7 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
from todoist.api import TodoistAPI from todoist.api import TodoistAPI
from datetime import datetime
import sys import sys
import time import time
import requests import requests
@ -51,8 +50,10 @@ def main():
'-ps', '--ps_suffix', help='Change suffix for parallel-sequential labeling (default "/-").', default='/-') '-ps', '--ps_suffix', help='Change suffix for parallel-sequential labeling (default "/-").', default='/-')
parser.add_argument( parser.add_argument(
'-sp', '--sp_suffix', help='Change suffix for sequential-parallel labeling (default "-/").', default='-/') '-sp', '--sp_suffix', help='Change suffix for sequential-parallel labeling (default "-/").', default='-/')
parser.add_argument('-hf', '--hide_future', help='Skip labelling future tasks after the specified number of days (default 7).', parser.add_argument(
default=7, type=int) '-hf', '--hide_future', help='Prevent labelling of future tasks beyond a specified number of days.', default = 0, type=int)
parser.add_argument(
'-df', '--dateformat', help='Strptime() format of starting date (default "%d-%m-%Y").', default = "%d-%m-%Y", type=str)
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(
@ -61,6 +62,7 @@ def main():
action='store_true') action='store_true')
parser.add_argument('--inbox', help='The method the Inbox should be processed with.', parser.add_argument('--inbox', help='The method the Inbox should be processed with.',
default=None, choices=['parallel', 'sequential']) default=None, choices=['parallel', 'sequential'])
args = parser.parse_args() args = parser.parse_args()
# Set debug # Set debug
@ -544,14 +546,36 @@ def main():
add_label(child_item, label_id) add_label(child_item, label_id)
# If item is too far in the future, remove the next_action tag and skip # If item is too far in the future, remove the next_action tag and skip
if args.hide_future > 0 and 'due_date_utc' in item.data and item['due_date_utc'] is not None: try:
due_date = datetime.strptime( if args.hide_future > 0 and 'due' in item.data and item['due'] is not None:
item['due_date_utc'], '%a %d %b %Y %H:%M:%S +0000') due_date = datetime.strptime(item['due']['date'], "%Y-%m-%d")
future_diff = ( future_diff = (due_date - datetime.today()).days
due_date - datetime.utcnow()).total_seconds() if future_diff >= args.hide_future:
if future_diff >= (args.hide_future * 86400):
remove_label(item, label_id) remove_label(item, label_id)
continue continue
except:
# Hide-future not set, skip
continue
# If start-date has not passed yet, remove label
try:
f = item['content'].find('start=')
if f > -1:
f_end = item['content'][f+6:].find(' ')
if f_end > -1:
start_date = item['content'][f+6:f+6+f_end]
else:
start_date = item['content'][f+6:]
start_date = datetime.strptime(start_date , args.dateformat)
future_diff = (datetime.today()-start_date).days
if future_diff < 0:
remove_label(item, label_id)
continue
except Exception as e:
logging.exception(
'Error start-date: %s' % str(e))
continue
# Commit the queue with changes # Commit the queue with changes
if label_id is not None: if label_id is not None: