|
|
|
@ -27,7 +27,7 @@ class Event: |
|
|
|
end, |
|
|
|
name, |
|
|
|
description=None, |
|
|
|
recurrence=None, |
|
|
|
recurrences=None, |
|
|
|
reminders=None, |
|
|
|
attendees=None, |
|
|
|
location=None, |
|
|
|
@ -39,7 +39,11 @@ class Event: |
|
|
|
self.name = name |
|
|
|
self.description = description |
|
|
|
self.location = location |
|
|
|
self.recurrence = recurrence |
|
|
|
|
|
|
|
if recurrences is None: |
|
|
|
self.recurrences = [] |
|
|
|
else: |
|
|
|
self.recurrences = recurrences |
|
|
|
self.id = id |
|
|
|
if reminders is None: |
|
|
|
self.reminders = {"useDefault": True} |
|
|
|
@ -63,26 +67,31 @@ class Event: |
|
|
|
def add_weekly_recurrence(self, until: datetime.datetime, *days): |
|
|
|
if not until.tzinfo: |
|
|
|
until = until.astimezone() |
|
|
|
ret = rrule.rrule( |
|
|
|
freq=rrule.WEEKLY, |
|
|
|
dtstart=self.start, |
|
|
|
wkst=weekdays.SUN, |
|
|
|
until=until, |
|
|
|
byweekday=days, |
|
|
|
self.recurrences.append( |
|
|
|
rrule.rrule( |
|
|
|
freq=rrule.WEEKLY, |
|
|
|
dtstart=self.start, |
|
|
|
wkst=weekdays.SUN, |
|
|
|
until=until, |
|
|
|
byweekday=days, |
|
|
|
) |
|
|
|
) |
|
|
|
ret_str = str(ret).split("\n")[-1] |
|
|
|
ret_str = re.sub(r"(UNTIL=[^;]+)", r"\1Z", ret_str) |
|
|
|
if self.recurrence is None: |
|
|
|
self.recurrence = [] |
|
|
|
self.recurrence.append(ret_str) |
|
|
|
|
|
|
|
def serialize_recurrences(self): |
|
|
|
for _rrule in self.recurrences: |
|
|
|
ret_str = str(_rrule).split("\n")[-1] |
|
|
|
ret_str = re.sub(r"(UNTIL=[^;]+)", r"\1Z", ret_str) |
|
|
|
yield ret_str |
|
|
|
|
|
|
|
def to_json(self): |
|
|
|
keys = ("attendees", "description", "location", "recurrence", "reminders") |
|
|
|
keys = ("attendees", "description", "location", "reminders") |
|
|
|
ret = { |
|
|
|
"summary": self.name, |
|
|
|
"start": to_dateTime(self.start), |
|
|
|
"end": to_dateTime(self.end), |
|
|
|
} |
|
|
|
for _rrule in self.serialize_recurrences(): |
|
|
|
ret.setdefault("recurrence", []).append(_rrule) |
|
|
|
for key in keys: |
|
|
|
try: |
|
|
|
value = self.__getattribute__(key) |
|
|
|
@ -101,7 +110,14 @@ class Event: |
|
|
|
args["name"] = body.get("summary", "unnamed") |
|
|
|
args["start"] = from_dateTime(body["start"]) |
|
|
|
args["end"] = from_dateTime(body["end"]) |
|
|
|
keys = ("attendees", "description", "location", "recurrence", "reminders", "id") |
|
|
|
keys = ( |
|
|
|
"attendees", |
|
|
|
"description", |
|
|
|
"location", |
|
|
|
"recurrences", |
|
|
|
"reminders", |
|
|
|
"id", |
|
|
|
) |
|
|
|
for key in keys: |
|
|
|
try: |
|
|
|
args[key] = body[key] |
|
|
|
|