-
Notifications
You must be signed in to change notification settings - Fork 9
/
build_event.py
59 lines (46 loc) · 1.68 KB
/
build_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
from icalendar import Calendar, Event
import pytz
from datetime import datetime, timedelta
def build_event_duration(
summary, description, start, duration, location, freq_of_recurrence, until
):
"""
Return an event that can be added to a calendar
summary: summary of the event
description: description of the event
location: self explanatory
start, end, stamp: These are datetime.datetime objects
freq_of_recurrence: frequency of recurrence, string which can take the
values daily, weekly, monthly, etc.
until: A datetime.datetime object which signifies when the recurrence will
end
"""
event = Event()
event.add("summary", summary)
event.add("description", description)
event.add("dtstart", start)
event.add("duration", timedelta(hours=duration))
event.add("dtstamp", datetime.now())
event.add("location", location)
event.add("rrule", {"FREQ": freq_of_recurrence, "UNTIL": until})
return event
def generateIndiaTime(year, month, date, hour, minutes):
return datetime(
year, month, date, hour, minutes, tzinfo=pytz.timezone("Asia/Kolkata")
)
if __name__ == "__main__":
cal = Calendar()
cal.add("prodid", "-//Your Timetable generated by GYFT//mxm.dk//")
cal.add("version", "1.0")
example_event = build_event_duration(
"example event",
"example event's description 2!",
generateIndiaTime(2016, 8, 22, 19, 0),
generateIndiaTime(2016, 8, 22, 20, 0),
"imaginary location!",
"weekly",
generateIndiaTime(2016, 11, 20, 12, 0),
)
cal.add_component(example_event)
with open("timetable.ics", "wb") as f:
f.write(cal.to_ical())