-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendarparse.py
More file actions
46 lines (34 loc) · 1.18 KB
/
calendarparse.py
File metadata and controls
46 lines (34 loc) · 1.18 KB
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from ics import Calendar, Event
from ics.timeline import Timeline
import arrow
def _complete_filename(filename):
return "/etc/openhab2/calendar/" + filename
def _find_events(day=None, file_or_list=None):
result_list = []
# default is today
d = arrow.utcnow() if (day is None) else arrow.get(day)
files = []
# can get simple str or complete list
if isinstance(file_or_list, str):
files.append(file_or_list)
else:
files = file_or_list
for file in files:
cal = Calendar(open(_complete_filename(file)).read())
tl = Timeline(cal)
# only one event can happen
names_list = []
for evt in tl.at(d):
names_list.append(evt.name)
if names_list:
result_list.append(', '.join(names_list))
return result_list
def _find_events_str(day, file_or_list):
events_list = _find_events(day=day, file_or_list=file_or_list)
return ', '.join(events_list)
def get_event_str(dayshift, file_or_list):
day = arrow.utcnow()
day = day.shift(days=dayshift)
return _find_events_str(day, file_or_list)