Implement the dateformat argument

pull/42/head
matthewanderson 2023-10-25 14:58:39 -05:00
parent 335cb3ae75
commit bb3bac88b6
1 changed files with 22 additions and 4 deletions

View File

@ -1365,12 +1365,30 @@ def autodoist_magic(args, api, connection):
# If start-date has not passed yet, remove label
try:
f1 = re.search(
'start=(\d{2}[-]\d{2}[-]\d{4})', task.content)
# When a user inputs a custom dateformat, they will use DD as day, MM as month, YYYY as year
# These values will be used as keys to retrieve a list of [regex, date format code]
# This list will then be used to reconstruct the proper regex search and date formatter below
date_dict = {
'DD': [r'\d{2}', '%d'],
'MM': [r'\d{2}', '%m'],
'YYYY': [r'\d{4}', '%Y']
}
# Currently we allow custom dates to be delimitted by '-' only.
# In the future logic could be added to hanlde '.' and '/' delimitters
custom_dateformat = args.dateformat.split("-")
# If there is a cleaner way retrieve the correct value from the dict above I'm all ears.
# For now I've made a tradeoff between readability and verbosity
regex_dateformat = f'{date_dict[custom_dateformat[0]][0]}[-]{date_dict[custom_dateformat[1]][0]}[-]{date_dict[custom_dateformat[2]][0]}'
parsed_dateformat = f'{date_dict[custom_dateformat[0]][1]}-{date_dict[custom_dateformat[1]][1]}-{date_dict[custom_dateformat[2]][1]}'
f1 = re.search(f'start=({regex_dateformat})', task.content)
if f1:
start_date = f1.groups()[0]
start_date = datetime.strptime(
start_date, args.dateformat)
start_date, parsed_dateformat)
future_diff = (
datetime.today()-start_date).days
# If start-date hasen't passed, remove all labels
@ -1463,7 +1481,7 @@ def main():
parser.add_argument(
'-s', '--s_suffix', help='change suffix for sequential labeling (default "-").', default='-')
parser.add_argument(
'-df', '--dateformat', help='[CURRENTLY DISABLED FEATURE] strptime() format of starting date (default "%%d-%%m-%%Y").', default='%d-%m-%Y')
'-df', '--dateformat', help='strptime() format of starting date (default "%%d-%%m-%%Y").', default='%d-%m-%Y')
parser.add_argument(
'-hf', '--hide_future', help='prevent labelling of future tasks beyond a specified number of days.', default=0, type=int)
parser.add_argument(