forked from HammerCloth/BangumiCalendar-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiCal.py
36 lines (28 loc) · 1.06 KB
/
iCal.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
from datetime import datetime
from icalendar import Calendar, Event
class iCal:
def __init__(self):
g = open("BEGIN:VCALENDAR.ics", "rb")
self.cal = Calendar.from_ical(g.read())
def display(self):
print(self.cal.to_ical().decode("utf-8").replace('\r\n', '\n').strip())
return self
def setEvent(self, summary, time, uuid, descripion):
event = Event()
event.add('dtstamp', datetime.today().date(), parameters={'VALUE': 'DATE'})
event.add('uid', uuid)
event.add('dtstart', time, parameters={'VALUE': 'DATE'})
event.add('class', 'PUBLIC')
event.add('summary', summary)
event.add("TRANSP", "TRANSPARENT")
event.add("description", descripion)
event.add("X-APPLE-UNIVERSAL-ID", "42902458-1dd4-5105-04d0-2dccc0194c5f")
self.cal.add_component(event)
return self
def write(self):
f = open("target.ics", "wb")
f.write(self.cal.to_ical())
f.close()
return self
if __name__ == '__main__':
iCal().display().write()