mirror of
https://github.com/javierpena/eink-calendar.git
synced 2024-11-16 20:25:58 +02:00
Add iCal support for calendars
We can now use an iCal URL as well as a CalDav one. iCal URLs are identified by a trailing ".ics" for now.
This commit is contained in:
parent
71fc4f8e37
commit
dd2a1b79a4
21
README.md
21
README.md
@ -39,7 +39,7 @@ owm_api_key = <insert API key here>
|
||||
owm_location = <insert location id here>
|
||||
|
||||
[calendar]
|
||||
urls = http://example.com/caldavcal1, http://example.com/caldavcal2, http://example.com/caldavcal3
|
||||
urls = http://example.com/caldavcal1, http://example.com/caldavcal2, http://example.com/ical3.ics
|
||||
names = user1, user2, user3
|
||||
username = user
|
||||
password = password
|
||||
@ -62,19 +62,24 @@ location id for your town, add them to the `owm_api_key` and `owm_location` keys
|
||||
the configuration file.
|
||||
|
||||
### Calendar configuration
|
||||
You can use any CalDav link; in my case, I set up 3 calendars in a [Synology](https://www.synology.com)
|
||||
DiskStation using Synology Calenar. The code should adapt to any number of calendars,
|
||||
You can use any CalDav or iCal link; in my case, I set up 3 calendars in a [Synology](https://www.synology.com)
|
||||
DiskStation using Synology Calendar. The code should adapt to any number of calendars,
|
||||
but keep in mind the resolution and font size.
|
||||
|
||||
The `urls` parameter is a comma-separated list of CalDav URLs. Since each of those
|
||||
calendars will correspond to an actual person, `names` will contain the list of
|
||||
names for each url. Make sure you spefify the same number of URLs and names.
|
||||
The `urls` parameter is a comma-separated list of CalDav or iCal URLs. Currently,
|
||||
iCal URLs are identified by a trailing `.ics` in the calendar URL. This may be
|
||||
improved in the future.
|
||||
|
||||
Since each of those calendars will correspond to an actual person, `names` will
|
||||
contain the list of names for each url. Make sure you spefify the same number
|
||||
of URLs and names.
|
||||
|
||||
The `username` and `password` fields are self-explaining: include the user and
|
||||
password to access the calendars.
|
||||
password to access the calendars, only for CalDav URLs.
|
||||
|
||||
If you want to use a different type of calendar, such as Google Calendar, you
|
||||
will need to create a new driver. Patches are welcome :).
|
||||
will need to create a new driver. However, it is possible to export a read-only,
|
||||
secret address for your Google Calendar following [this guide](https://support.google.com/calendar/answer/37648?hl=en#zippy=%2Cget-your-calendar-view-only).
|
||||
|
||||
## Running
|
||||
The scripts directory contains a simple launcher script using a virtual environment,
|
||||
|
@ -13,8 +13,8 @@ owm_api_key = <insert API key here>
|
||||
owm_location = <insert location id here>
|
||||
|
||||
[calendar]
|
||||
# URL of all caldav calendars, separated by commas
|
||||
urls = http://example.com/caldavcal1, http://example.com/caldavcal2, http://example.com/caldavcal3
|
||||
# URL of all caldav or iCal calendars, separated by commas
|
||||
urls = http://example.com/caldavcal1, http://example.com/caldavcal2, http://example.com/ical3.ics
|
||||
names = user1, user2, user3
|
||||
username = user
|
||||
password = password
|
||||
|
29
drivers/icalprovider.py
Normal file
29
drivers/icalprovider.py
Normal file
@ -0,0 +1,29 @@
|
||||
from datetime import datetime
|
||||
from icalevents import icalevents
|
||||
|
||||
import icalendar
|
||||
import pytz
|
||||
import urllib3
|
||||
|
||||
urllib3.disable_warnings()
|
||||
|
||||
class ICalProvider():
|
||||
def __init__(self):
|
||||
self.tz = pytz.timezone('Europe/Madrid')
|
||||
|
||||
def get_calendar(self, url, date_start, date_end):
|
||||
#print("%s %s" % (date_start, date_end))
|
||||
returned_events = []
|
||||
try:
|
||||
events_found = icalevents.events(url=url, start=date_start, end=date_end)
|
||||
if events_found:
|
||||
for event in events_found:
|
||||
single_event = {}
|
||||
single_event['event_start'] = event.start.astimezone(self.tz)
|
||||
single_event['event_end'] = event.end.astimezone(self.tz)
|
||||
single_event['event_title'] = event.summary
|
||||
returned_events.append(single_event)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return returned_events
|
@ -9,6 +9,7 @@ import sys
|
||||
import time
|
||||
|
||||
from drivers.caldavprovider import CalDavProvider
|
||||
from drivers.icalprovider import ICalProvider
|
||||
from widgets.calendarwidget import CalendarWidget
|
||||
from widgets.timewidget import TimeWidget
|
||||
from widgets.weatherwidget import WeatherWidget
|
||||
@ -22,13 +23,18 @@ def today_calendar():
|
||||
fullimg.paste(timewidget.get_time(), box=(128, 0))
|
||||
calendar = CalendarWidget(family_names)
|
||||
event_getter = CalDavProvider(calendar_username, calendar_password)
|
||||
ical_event_getter = ICalProvider()
|
||||
test_event_list = []
|
||||
|
||||
today_start = datetime.now().replace(hour=8, minute=0, second=0, microsecond=0)
|
||||
today_end = today_start.replace(hour=21, minute=0, second=0, microsecond=0)
|
||||
|
||||
for url in calendar_list:
|
||||
test_event_list.append(event_getter.get_calendar(url, today_start, today_end))
|
||||
if url.endswith('.ics'):
|
||||
# This is an iCal URL
|
||||
test_event_list.append(ical_event_getter.get_calendar(url, today_start, today_end))
|
||||
else:
|
||||
test_event_list.append(event_getter.get_calendar(url, today_start, today_end))
|
||||
img1, img2 = calendar.get_calendar(test_event_list)
|
||||
fullimg.paste(img1, box=(0, 80))
|
||||
fullimg2.paste(img2, box=(0, 80))
|
||||
@ -42,6 +48,7 @@ def week_calendar(calid, name):
|
||||
timewidget = TimeWidget()
|
||||
fullimg.paste(timewidget.get_time(), box=(128, 0))
|
||||
event_getter = CalDavProvider(calendar_username, calendar_password)
|
||||
ical_event_getter = ICalProvider()
|
||||
test_event_list = []
|
||||
|
||||
today = datetime.today()
|
||||
@ -49,7 +56,12 @@ def week_calendar(calid, name):
|
||||
curdate = curdate.replace(hour=8, minute=0, second=0, microsecond=0)
|
||||
|
||||
for day in range(7, 12):
|
||||
test_event_list.append(event_getter.get_calendar(calendar_list[calid], curdate, curdate.replace(hour=21)))
|
||||
if calendar_list[calid].endswith('.ics'):
|
||||
# iCal calendar
|
||||
test_event_list.append(ical_event_getter.get_calendar(calendar_list[calid], curdate, curdate.replace(hour=21)))
|
||||
else:
|
||||
# CalDAV
|
||||
test_event_list.append(event_getter.get_calendar(calendar_list[calid], curdate, curdate.replace(hour=21)))
|
||||
curdate = curdate + timedelta(days=1)
|
||||
|
||||
calendar = CalendarWidget(['L', 'M', 'X', 'J', 'V'])
|
||||
|
@ -1,5 +1,6 @@
|
||||
caldav
|
||||
icalendar
|
||||
icalevents
|
||||
pygame
|
||||
pillow
|
||||
pyowm
|
||||
|
Loading…
Reference in New Issue
Block a user