57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
import os
|
|
import os.path
|
|
import tempfile
|
|
from icalendar import Calendar, Event
|
|
from webdav3.client import Client as WDClient
|
|
|
|
|
|
class Client:
|
|
def __init__(self, config):
|
|
"""
|
|
Initializes a client
|
|
"""
|
|
options = {
|
|
'webdav_hostname': config["WEBDAV_SERVER"],
|
|
'webdav_login': config["WEBDAV_USER"],
|
|
'webdav_password': config["WEBDAV_PASSWORD"],
|
|
}
|
|
self.calendar_path = config["CALENDAR_PATH"]
|
|
self.client = WDClient(options)
|
|
|
|
def retrieve_calendars_list(self):
|
|
"""
|
|
Retrieves the calendar list
|
|
"""
|
|
return self.client.list(self.path)
|
|
|
|
def read_calendar(self, pathname):
|
|
"""
|
|
Given a filename, tries to read the calendar event
|
|
"""
|
|
f, temp_path = tempfile.mkstemp()
|
|
rpath = os.path.join(self.calendar_path, pathname)
|
|
self.client.download_sync(remote_path=rpath,
|
|
local_path=temp_path)
|
|
# Read the temporary data, close the file, remove it
|
|
data = f.read()
|
|
f.close()
|
|
os.remove(temp_path)
|
|
# Now with the data read, we can process it
|
|
return self.parse_calendar(data)
|
|
|
|
def parse_calendar(self, data):
|
|
"""
|
|
Parses ICS calendar data received
|
|
"""
|
|
calendar = Calendar.from_ical(data)
|
|
for component in calendar.walk():
|
|
if component.name == 'VEVENT':
|
|
pass
|
|
|
|
|
|
|
|
def get_todays_events(self):
|
|
"""
|
|
Get todays events
|
|
"""
|
|
pass
|