mirror of
https://git.webmeisterei.com/webmeisterei/todoist-taskwarrior.git
synced 2023-12-21 10:23:00 +01:00
Handle recurring tasks from date_string (recur)
This commit is contained in:
parent
e4d86e1ab3
commit
40e5fcb07e
58
migrate.py
58
migrate.py
@ -1,4 +1,5 @@
|
|||||||
import click
|
import click
|
||||||
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from taskw import TaskWarrior
|
from taskw import TaskWarrior
|
||||||
from todoist.api import TodoistAPI
|
from todoist.api import TodoistAPI
|
||||||
@ -40,14 +41,15 @@ def migrate(interactive, no_sync):
|
|||||||
]
|
]
|
||||||
entry = taskwarrior_date(task['date_added'])
|
entry = taskwarrior_date(task['date_added'])
|
||||||
due = taskwarrior_date(task['due_date_utc'])
|
due = taskwarrior_date(task['due_date_utc'])
|
||||||
|
recur = taskwarrior_recur(task['date_string'])
|
||||||
|
|
||||||
if interactive and not click.confirm(f"Import '{name}'?"):
|
if interactive and not click.confirm(f"Import '{name}'?"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
add_task(tid, name, project, tags, priority, entry, due)
|
add_task(tid, name, project, tags, priority, entry, due, recur)
|
||||||
|
|
||||||
|
|
||||||
def add_task(tid, name, project, tags, priority, entry, due):
|
def add_task(tid, name, project, tags, priority, entry, due, recur):
|
||||||
"""Add a taskwarrior task from todoist task
|
"""Add a taskwarrior task from todoist task
|
||||||
|
|
||||||
Returns the taskwarrior task.
|
Returns the taskwarrior task.
|
||||||
@ -55,7 +57,7 @@ def add_task(tid, name, project, tags, priority, entry, due):
|
|||||||
info(f"Importing '{name}' ({project}) - ", nl=False)
|
info(f"Importing '{name}' ({project}) - ", nl=False)
|
||||||
try:
|
try:
|
||||||
tw_task = taskwarrior.task_add(name, project=project, tags=tags,
|
tw_task = taskwarrior.task_add(name, project=project, tags=tags,
|
||||||
priority=priority, entry=entry, due=due)
|
priority=priority, entry=entry, due=due, recur=recur)
|
||||||
except:
|
except:
|
||||||
error('FAILED')
|
error('FAILED')
|
||||||
else:
|
else:
|
||||||
@ -83,7 +85,7 @@ def taskwarrior_priority(priority):
|
|||||||
return PRIORITIES[priority]
|
return PRIORITIES[priority]
|
||||||
|
|
||||||
def taskwarrior_date(date):
|
def taskwarrior_date(date):
|
||||||
""" Converts a date from Todist to taskwarrior
|
""" Converts a date from Todoist to taskwarrior
|
||||||
|
|
||||||
Todoist: Fri 26 Sep 2014 08:25:05 +0000 (what is this called)?
|
Todoist: Fri 26 Sep 2014 08:25:05 +0000 (what is this called)?
|
||||||
taskwarrior: ISO-8601
|
taskwarrior: ISO-8601
|
||||||
@ -92,6 +94,54 @@ def taskwarrior_date(date):
|
|||||||
return None
|
return None
|
||||||
return datetime.strptime(date, '%a %d %b %Y %H:%M:%S %z').isoformat()
|
return datetime.strptime(date, '%a %d %b %Y %H:%M:%S %z').isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
def taskwarrior_recur(desc):
|
||||||
|
""" Converts a repeating interval from Todoist to taskwarrior.
|
||||||
|
|
||||||
|
Field:
|
||||||
|
- Todoist: date_string
|
||||||
|
- taskwarrior: recur
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
- every other `interval` `period` -> 2 `period`
|
||||||
|
- every `interval` `period` -> `interval` `period`
|
||||||
|
- every `day of week` -> weekly
|
||||||
|
|
||||||
|
_Note_: just because Todoist sets `date_string` doesn't mean
|
||||||
|
that the task is repeating. Mostly it just indicates that the
|
||||||
|
user input via string and not date selector.
|
||||||
|
"""
|
||||||
|
if not desc:
|
||||||
|
return
|
||||||
|
return _match_every(desc) or _match_weekly(desc)
|
||||||
|
|
||||||
|
|
||||||
|
RE_INTERVAL = 'other|\d+'
|
||||||
|
RE_PERIOD = 'day|week|month|year'
|
||||||
|
RE_REPEAT_EVERY = re.compile(
|
||||||
|
f'^\s*every\s+((?P<interval>{RE_INTERVAL})\s+)?(?P<period>{RE_PERIOD})s?\s*$'
|
||||||
|
)
|
||||||
|
|
||||||
|
def _match_every(desc):
|
||||||
|
match = RE_REPEAT_EVERY.match(desc.lower())
|
||||||
|
if not match:
|
||||||
|
return
|
||||||
|
|
||||||
|
interval = match.group('interval')
|
||||||
|
period = match.group('period')
|
||||||
|
if interval == 'other':
|
||||||
|
interval = 2
|
||||||
|
return f'{interval} {period}'
|
||||||
|
|
||||||
|
|
||||||
|
RE_REPEAT_WEEKLY = re.compile(
|
||||||
|
'^\s*every\s+(mon|monday|tues|tuesday|weds|wednesday|thurs|thursday|fri|friday|sat|saturday|sun|sunday)\s*'
|
||||||
|
)
|
||||||
|
|
||||||
|
def _match_weekly(desc):
|
||||||
|
return ('weekly' if RE_REPEAT_WEEKLY.match(desc.lower()) else None)
|
||||||
|
|
||||||
|
|
||||||
""" Entrypoint """
|
""" Entrypoint """
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user