Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New CalDAV description format #112

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/readme-tw-caldav.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ TW <-> Caldav will make the following mappings between items:
- `L` <-> 9
- `M` <-> 5
- `H` <-> 1
- TW `annotations`, `uuid` <-> `DESCRIPTION`
- TW `annotations` <-> `DESCRIPTION` (one annotation <-> one line in description)
- TW `uuid` <-> `X-SYNCALL-TW-UUID`
- TW `tags` <-> `CATEGORIES`

### Current limitations
Expand Down
2 changes: 2 additions & 0 deletions syncall/caldav/caldav_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CaldavSide(SyncSide):
"status",
"summary",
"due",
"x-syncall-tw-uuid",
)

_date_keys: tuple[str] = ("end", "start", "last-modified")
Expand Down Expand Up @@ -144,6 +145,7 @@ def add_item(self, item):
categories=item.get("categories"),
created=item.get("created"),
completed=item.get("completed"),
x_syncall_tw_uuid=item.get("x-syncall-tw-uuid"),
)
return map_ics_to_item(icalendar_component(todo))

Expand Down
1 change: 1 addition & 0 deletions syncall/caldav/caldav_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _convert_one(name: str) -> str:
todo_item[name] = _convert_one(name).lower()
for name in ["description", "summary"]:
todo_item[name] = _convert_one(name)
todo_item["uuid"] = _convert_one("x-syncall-tw-uuid")

for date_field in ("due", "created", "completed", "last-modified"):
if vtodo.get(date_field):
Expand Down
51 changes: 26 additions & 25 deletions syncall/tw_caldav_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ def convert_tw_to_caldav(tw_item: Item) -> Item:

caldav_item["summary"] = tw_item["description"]
# description
caldav_item["description"] = "IMPORTED FROM TASKWARRIOR\n"
if "annotations" in tw_item:
for i, annotation in enumerate(tw_item["annotations"]):
caldav_item["description"] += f"\n* Annotation {i + 1}: {annotation}"
if "annotations" in tw_item.keys():
caldav_item["description"] = "\n".join(tw_item["annotations"])

caldav_item["description"] += "\n"
caldav_item["description"] += f'\n* uuid: {tw_item["uuid"]}'
# uuid
caldav_item["x-syncall-tw-uuid"] = f'{tw_item["uuid"]}'

# Status
caldav_item["status"] = aliases_tw_caldav_status[tw_item["status"]]
Expand Down Expand Up @@ -77,7 +75,7 @@ def convert_tw_to_caldav(tw_item: Item) -> Item:


def convert_caldav_to_tw(caldav_item: Item) -> Item:
# Parse the description
# Parse the description by old format
annotations, uuid = parse_caldav_item_desc(caldav_item)
assert isinstance(annotations, list)
assert isinstance(uuid, UUID) or uuid is None
Expand All @@ -91,33 +89,36 @@ def convert_caldav_to_tw(caldav_item: Item) -> Item:

tw_item["description"] = caldav_item.get("summary")
tw_item["annotations"] = annotations
if uuid is not None:
if uuid is not None: # old format
tw_item["uuid"] = uuid
else: # uuid not found, try new format
if "description" in caldav_item.keys():
tw_item["annotations"] = [
line.strip() for line in caldav_item["description"].split("\n") if line
]
if "x-syncall-tw-uuid" in caldav_item.keys():
tw_item["uuid"] = UUID(caldav_item["x-syncall-tw-uuid"])

# Status
tw_item["status"] = aliases_caldav_tw_status[caldav_item["status"]]

# Priority
prio = aliases_caldav_tw_priority.get(caldav_item["priority"])
if prio:
if prio := aliases_caldav_tw_priority.get(caldav_item["priority"]):
tw_item["priority"] = prio

# Timestamps
if "created" in caldav_item:
tw_item["entry"] = caldav_item["created"]
if "completed" in caldav_item:
tw_item["end"] = caldav_item["completed"]
if "last-modified" in caldav_item:
tw_item["modified"] = caldav_item["last-modified"]

# Start/due dates
if "due" in caldav_item:
tw_item["due"] = caldav_item["due"]

if "categories" in caldav_item:
tw_item["tags"] = caldav_item["categories"]

# start time
if caldav_item["status"] == "in-process" and "last-modified" in caldav_item:
tw_item["start"] = caldav_item["last-modified"]

# Rest of properties
for caldav_key, tw_key in (
("created", "entry"),
("completed", "end"),
("last-modified", "modified"),
("due", "due"),
("categories", "tags"),
):
if caldav_key in caldav_item:
tw_item[tw_key] = caldav_item[caldav_key]

return tw_item
41 changes: 12 additions & 29 deletions tests/test_data/sample_items.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,25 @@ tw_item_w_due:
- This is the annotation text
- This is the other annotation text
caldav_item_expected:
description: 'IMPORTED FROM TASKWARRIOR


* Annotation 1: This is the annotation text

* Annotation 2: This is the other annotation text


* uuid: 00208973-20da-4988-ae3e-58ef3650c363'
description: |-
This is the annotation text
This is the other annotation text
summary: Kalimera!
last-modified: 2019-03-05 00:03:09
status: 'needs-action'
categories: ['remindme']
x-syncall-tw-uuid: '00208973-20da-4988-ae3e-58ef3650c363'
caldav_item_w_date_expected:
description: 'IMPORTED FROM TASKWARRIOR


* Annotation 1: This is the annotation text

* Annotation 2: This is the other annotation text


* uuid: 00208973-20da-4988-ae3e-58ef3650c363'
description: |-
This is the annotation text
This is the other annotation text
due: 2019-03-09 00:00:00
start: 2019-03-08 23:00:00
summary: Kalimera!
last-modified: 2019-03-05 00:03:09
status: 'needs-action'
categories: ['remindme']
x-syncall-tw-uuid: '00208973-20da-4988-ae3e-58ef3650c363'
gcal_item_expected:
description: 'IMPORTED FROM TASKWARRIOR

Expand Down Expand Up @@ -150,24 +140,17 @@ gcal_item:
summary: another summary goes here
updated: '2019-03-08T00:29:06.602Z'
caldav_item:
description: '

The same old description


* Annotation 1: kalimera

* Annotation 2: kalinuxta kai kali vradia


* uuid: 00208973-20da-4988-ae3e-58ef3650c363'
description: |-
kalimera
kalinuxta kai kali vradia
due: 2019-03-04 05:00:00
id: 52ggba92l9ph4d0ghabi3ohdh7
start: 2019-03-04 04:00:00
status: 'needs-action'
summary: another summary goes here
last-modified: 2019-03-08 00:29:06.602
priority: ''
x-syncall-tw-uuid: '00208973-20da-4988-ae3e-58ef3650c363'
tw_item_expected:
syncallduration: "PT3600S"
annotations:
Expand Down