-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathics.py
More file actions
33 lines (25 loc) · 969 Bytes
/
Copy pathics.py
File metadata and controls
33 lines (25 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import List
class CalendarEvent:
def __init__(self, task):
self.uid = task.id
self.summary = escape_human_readable_text(task.title)
self.description = escape_human_readable_text(task.description)
self.dtstamp = format_date_time(task.created)
self.dtstart = format_date_time(task.due)
self.dtend = format_date_time(task.due)
class VCalendar:
def __init__(self, prod_id: str, name: str, events: List[CalendarEvent]):
self.prod_id = prod_id
self.name = escape_human_readable_text(name)
self.events = events
def format_date_time(date_time):
if date_time is None:
return ""
return date_time.strftime("%Y%m%dT%H%M%SZ")
def escape_human_readable_text(text: str):
return text.replace(r'\N', '\n') \
.replace('\\', '\\\\') \
.replace(';', r'\;') \
.replace(',', r'\,') \
.replace('\r\n', r'\n') \
.replace('\n', r'\n')