-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfullcalendar_event.py
60 lines (49 loc) · 1.18 KB
/
fullcalendar_event.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from exchangelib import EWSTimeZone
import os, tzlocal
TIMEZONE = os.environ.get('EWS_TIMEZONE', tzlocal.get_localzone().zone)
TZ = EWSTimeZone.timezone(TIMEZONE)
class FullCalendarEvent(object):
optional_props = [
'id',
'all_day',
'end',
'url',
'location',
'description'
]
dict_keys = {
'all_day': 'allDay'
}
def __init__(self, title, start, **kwargs):
for k in kwargs.keys():
self.title = title
self.start = start
if k in self.optional_props:
self.__setattr__(k, kwargs[k])
@classmethod
def from_ews_event(cls, event):
description = None
if event.text_body and event.text_body.strip():
description = event.text_body.strip()
return cls(
id=event.item_id,
title=event.subject,
start=event.start.astimezone(TZ).isoformat(),
end=event.end.astimezone(TZ).isoformat(),
all_day=event.is_all_day,
location=event.location,
description=description
)
def to_dict(self):
d = {
'title': self.title,
'start': self.start
}
for k in self.optional_props:
try:
v = self.__getattribute__(k)
dict_key = self.dict_keys[k] if k in self.dict_keys.keys() else k
d[dict_key] = v
except AttributeError:
pass
return d