mirror of
https://git.webmeisterei.com/webmeisterei/todoist-taskwarrior.git
synced 2023-12-21 10:23:00 +01:00
Update to todoist-python 8.0.0
This commit is contained in:
@ -146,8 +146,8 @@ def migrate(ctx, interactive, sync, map_project, map_tag):
|
||||
|
||||
# Dates
|
||||
data['entry'] = utils.parse_date(task['date_added'])
|
||||
data['due'] = utils.parse_date(task['due_date_utc'])
|
||||
data['recur'] = parse_recur_or_prompt(task['date_string'])
|
||||
data['due'] = utils.parse_due(utils.try_get_model_prop(task, 'due'))
|
||||
data['recur'] = parse_recur_or_prompt(utils.try_get_model_prop(task, 'due'))
|
||||
|
||||
if not interactive:
|
||||
add_task(**data)
|
||||
@ -279,11 +279,11 @@ def add_task_interactive(**task_data):
|
||||
return add_task(**task_data)
|
||||
|
||||
|
||||
def parse_recur_or_prompt(value):
|
||||
def parse_recur_or_prompt(due):
|
||||
try:
|
||||
return utils.parse_recur(value)
|
||||
return utils.parse_recur(due)
|
||||
except errors.UnsupportedRecurrence:
|
||||
io.error('Unsupported recurrence: %s. Please enter a valid value' % value)
|
||||
io.error("Unsupported recurrence: '%s'. Please enter a valid value" % due['string'])
|
||||
return io.prompt(
|
||||
'Set recurrence (todoist style)',
|
||||
default='',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import click
|
||||
import re
|
||||
from datetime import datetime
|
||||
import dateutil.parser
|
||||
from .errors import UnsupportedRecurrence
|
||||
|
||||
|
||||
@ -14,6 +14,14 @@ def try_map(m, value):
|
||||
return value
|
||||
|
||||
|
||||
def try_get_model_prop(m, key, default=None):
|
||||
""" The todoist models don't seem to have the `get()` method and throw KeyErrors """
|
||||
try:
|
||||
return m[key]
|
||||
except KeyError:
|
||||
return default
|
||||
|
||||
|
||||
""" Priorities """
|
||||
|
||||
PRIORITY_MAP = {1: None, 2: 'L', 3: 'M', 4: 'H'}
|
||||
@ -38,6 +46,23 @@ def maybe_quote_ws(value):
|
||||
|
||||
""" Dates """
|
||||
|
||||
def parse_due(due):
|
||||
"""Parse a due date from the due object.
|
||||
|
||||
e.g. {
|
||||
"date": "2016-12-0T12:00:00",
|
||||
"timezone": null,
|
||||
"string": "every day at 12",
|
||||
"lang": "en",
|
||||
"is_recurring": true
|
||||
}
|
||||
"""
|
||||
if not due:
|
||||
return None
|
||||
|
||||
return parse_date(due['date'])
|
||||
|
||||
|
||||
def parse_date(date):
|
||||
""" Converts a date from Todoist to Taskwarrior.
|
||||
|
||||
@ -47,10 +72,17 @@ def parse_date(date):
|
||||
if not date:
|
||||
return None
|
||||
|
||||
return datetime.strptime(date, '%a %d %b %Y %H:%M:%S %z').isoformat()
|
||||
return dateutil.parser.parse(date).isoformat()
|
||||
|
||||
|
||||
def parse_recur(date_string):
|
||||
def parse_recur(due):
|
||||
"""Given a due object, extracts the recur """
|
||||
if not due or not due['is_recurring']:
|
||||
return None
|
||||
return parse_recur_string(due['string'])
|
||||
|
||||
|
||||
def parse_recur_string(date_string):
|
||||
""" Parses a Todoist `date_string` to extract a `recur` string for Taskwarrior.
|
||||
|
||||
Field:
|
||||
|
@ -18,6 +18,6 @@ def validate_map(ctx, param, value):
|
||||
|
||||
def validate_recur(value):
|
||||
try:
|
||||
return utils.parse_recur(value)
|
||||
return utils.parse_recur_string(value)
|
||||
except errors.UnsupportedRecurrence as e:
|
||||
raise click.BadParameter(e)
|
||||
|
Reference in New Issue
Block a user