-
Notifications
You must be signed in to change notification settings - Fork 2
/
Event.py
147 lines (122 loc) · 3.35 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# vi:si:noet:sw=4:sts=4:ts=8
#
# Erminig-NG (A two-way synchronization tool for Google-Calendar and
# "Fremantle-Calendar", the calendar of Maemo 5)
#
# Copyright (c) 2010 Pascal Jermini <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# version 2.1, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to:
#
# Free Software Foundation, Inc.
# 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import iso8601
import logger
class Event:
def __init__(self, title, where, descr, start_time, end_time, \
full_day, id, cdate, rrule=None, alarm=-1):
self.title = title
self.where = where
self.descr = descr
self.start_time = start_time
self.end_time = end_time
self.full_day = full_day
self.cdate = cdate
self.id = id
self.tzOffset = 0
self.rrule = rrule
self.alarm = alarm
def set_tzOffset(self, o):
self.tzOffset = o
def get_tzOffset(self):
return self.tzOffset
def eval(self, var):
if var:
return var
else:
return ""
def get_title(self):
return self.eval(self.title)
def get_where(self):
return self.eval(self.where)
def get_start(self):
return int(self.start_time)
def get_end(self):
if self.full_day == 1:
# we have to take off 1 second in case of full-day
# events, to make Fremantle Calendar happy
return int(self.end_time - 1)
else:
return int(self.end_time)
def get_description(self):
return self.eval(self.descr)
def get_id(self):
return self.eval(self.id)
def get_fullday(self):
return self.full_day
def get_cdate(self):
return int(self.cdate)
def get_until(self):
if self.rrule == None or self.rrule == "":
return -1
rules = self.rrule.split(";")
print rules
d = ""
for r in rules:
if r.startswith("UNTIL="):
d = r[len("UNTIL="):]
break
if len(d) == 8:
iso_date = d[:4] + "-" + d[4:6] + "-" + d[6:]
elif len(d) == 15:
iso_date = d[:4] + "-" + d[4:6] + "-" + d[6:11] \
+ ":" + d[11:13] + ":" + d[13:]
else:
logger.append("event %s: strange until value: %s" % (self.title, d))
return -1
# ??
return int(iso8601.parse(iso_date)) + 1
def get_rrule(self):
return self.rrule
def get_rtype(self):
if self.rrule.find("YEARLY") <> -1:
return 5
elif self.rrule.find("MONTHLY") <> -1:
return 4
elif self.rrule.find("DAILY") <> -1:
return 1
elif self.rrule.find("WEEKLY") <> -1:
# look if all weekdays are listed:
start = self.rrule.find("BYDAY=")
end1 = self.rrule.find(";", start)
end2 = self.rrule.find("!", start)
days = self.rrule[start+len(self.rrule):min(end1,end2)]
days_a = days.split(",")
if len(days_a) <> 5:
return 3
else:
if days_a.count("MO") and days_a.count("TU") \
and days_a.count("WE") \
and days_a.count("TH") \
and days_a.count("FR"):
return 2
else:
return 3
else:
return 0
def get_alarm(self):
"""
@rtype: str
"""
return str(self.alarm)