summaryrefslogtreecommitdiff
path: root/cal.py
diff options
context:
space:
mode:
Diffstat (limited to 'cal.py')
-rw-r--r--cal.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/cal.py b/cal.py
new file mode 100644
index 0000000..4f32465
--- /dev/null
+++ b/cal.py
@@ -0,0 +1,46 @@
+import icalendar
+import recurring_ical_events
+import urllib.request
+import datetime
+from settings import calendars
+
+today = datetime.date.today()
+output = []
+
+'''
+ For some reason Icloud calendars seem to be reversed,
+ so the must be reversed to put events in the proper order.
+'''
+
+
+def isIcloud(url):
+ index = url.find("icloud")
+ if index > -1:
+ return True
+ return False
+
+
+def getEvents(url, cName):
+ ical_string = urllib.request.urlopen(url).read()
+ calendar = icalendar.Calendar.from_ical(ical_string)
+ events = recurring_ical_events.of(calendar).at(today)
+ if len(events) != 0:
+ if isIcloud(url):
+ events.reverse()
+ output.append(f"\nToday's events from {cName} calendar:")
+ for event in events:
+ name = event["SUMMARY"]
+ try:
+ start = event["DTSTART"].dt.strftime("%H:%M")
+ end = event["DTEND"].dt.strftime("%H:%M")
+ output.append(f"{name} from {start} to {end}")
+ except:
+ output.append(f"{name} All Day")
+
+
+def getEventsFromCal():
+ for calendar in calendars:
+ url = calendars[calendar]
+ getEvents(url, calendar)
+ output[-1] = output[-1] + "\n"
+ return output