-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
calendar_caldav.py
53 lines (48 loc) · 1.81 KB
/
calendar_caldav.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
# Support module that contains classes used from main script
import datetime
import caldav
class Calendar:
"""
Represents one server that will be loaded.
"""
def __init__(self, url, user, password):
with caldav.DAVClient(
url=url,
username=user,
password=password,
) as client:
self.principal = client.principal()
self.calendar_list = [x.name for x in self.principal.calendars()]
self.calendar_list.sort()
class Event:
"""
Represent one event loaded from caldav.
"""
def __init__(self, name, calendar, start, end, location, description):
self.name = name
self.calendar = calendar
self.start = start
self.end = end
self.location = location
if self.location == None:
self.location = ""
self.description = description
if self.description == None:
self.description = ""
# Functions below were added due to sort function.
def __eq__(self, other):
zacatek1 = self.start
if type(zacatek1) is datetime.date:
zacatek1 = datetime.datetime.combine(zacatek1, datetime.datetime.min.time())
zacatek2 = other.start
if type(zacatek2) is datetime.date:
zacatek2 = datetime.datetime.combine(zacatek2, datetime.datetime.min.time())
return zacatek1.timestamp() == zacatek2.timestamp()
def __lt__(self, other):
zacatek1 = self.start
if type(zacatek1) is datetime.date:
zacatek1 = datetime.datetime.combine(zacatek1, datetime.datetime.min.time())
zacatek2 = other.start
if type(zacatek2) is datetime.date:
zacatek2 = datetime.datetime.combine(zacatek2, datetime.datetime.min.time())
return zacatek1.timestamp() < zacatek2.timestamp()