mirror of
https://github.com/javierpena/eink-calendar.git
synced 2024-11-16 20:25:58 +02:00
Some improvements
- Allow one extra hour for calendar events - Improve resiliency if something fails when checking the weather or calendar API.
This commit is contained in:
parent
24ffae2a97
commit
71fc4f8e37
@ -15,24 +15,26 @@ class CalDavProvider():
|
||||
|
||||
def get_calendar(self, url, date_start, date_end):
|
||||
# print("%s %s" % (date_start, date_end))
|
||||
client = caldav.DAVClient(url=url, username=self.username, password=self.password, ssl_verify_cert=False)
|
||||
calendar = caldav.Calendar(client=client, url=url)
|
||||
returned_events = []
|
||||
|
||||
events_found = calendar.date_search(
|
||||
start=date_start, end=date_end,
|
||||
compfilter='VEVENT', expand=True)
|
||||
if events_found:
|
||||
for event in events_found:
|
||||
cal = icalendar.Calendar.from_ical(event.data)
|
||||
single_event = {}
|
||||
for event in cal.walk('vevent'):
|
||||
date_start = event.get('dtstart')
|
||||
duration = event.get('duration')
|
||||
summary = event.get('summary')
|
||||
single_event['event_start'] = date_start.dt.astimezone(self.tz)
|
||||
single_event['event_end'] = (date_start.dt + duration.dt).astimezone(self.tz)
|
||||
single_event['event_title'] = summary
|
||||
returned_events.append(single_event)
|
||||
try:
|
||||
client = caldav.DAVClient(url=url, username=self.username, password=self.password, ssl_verify_cert=False)
|
||||
calendar = caldav.Calendar(client=client, url=url)
|
||||
events_found = calendar.date_search(
|
||||
start=date_start, end=date_end,
|
||||
compfilter='VEVENT', expand=True)
|
||||
if events_found:
|
||||
for event in events_found:
|
||||
cal = icalendar.Calendar.from_ical(event.data)
|
||||
single_event = {}
|
||||
for event in cal.walk('vevent'):
|
||||
date_start = event.get('dtstart')
|
||||
duration = event.get('duration')
|
||||
summary = event.get('summary')
|
||||
single_event['event_start'] = date_start.dt.astimezone(self.tz)
|
||||
single_event['event_end'] = (date_start.dt + duration.dt).astimezone(self.tz)
|
||||
single_event['event_title'] = summary
|
||||
returned_events.append(single_event)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return returned_events
|
||||
|
@ -138,7 +138,7 @@ try:
|
||||
refresh = True
|
||||
else:
|
||||
current_time = datetime.now()
|
||||
if current_time.hour > 20 or current_time.hour < 7:
|
||||
if current_time.hour > 21 or current_time.hour < 7:
|
||||
current_screen = 4
|
||||
else:
|
||||
current_screen = 0
|
||||
|
@ -63,13 +63,13 @@ class CalendarWidget():
|
||||
# Draw Calendar lines
|
||||
for i in range(0, 14):
|
||||
imgdraw2.line([(0,30 + 20*i), (639, 30 + 20*i)], fill=0, width=1)
|
||||
for i in range(0, 13):
|
||||
for i in range(0, 14):
|
||||
imgdraw.text((0, 30 + 20*i), '%2d:00' % (i+8), font=self.font14, fill=0)
|
||||
|
||||
column_number = 0
|
||||
for column_list in column_events:
|
||||
for event in column_list:
|
||||
if event['event_start'].hour >= 8 or event['event_start'].hour <= 19:
|
||||
if event['event_start'].hour >= 8 and event['event_start'].hour <= 21:
|
||||
eventimg = self.create_entry_box(event['event_start'],
|
||||
event['event_end'],
|
||||
event['event_title'],
|
||||
|
@ -10,11 +10,15 @@ class WeatherWidget():
|
||||
self.owm = OWM(api_key)
|
||||
|
||||
def get_weather(self, location):
|
||||
mgr = self.owm.weather_manager()
|
||||
current = mgr.weather_at_id(location)
|
||||
w = current.weather
|
||||
temp = w.temperature('celsius')['temp']
|
||||
wcode = w.weather_code
|
||||
try:
|
||||
mgr = self.owm.weather_manager()
|
||||
current = mgr.weather_at_id(location)
|
||||
w = current.weather
|
||||
temp = w.temperature('celsius')['temp']
|
||||
wcode = w.weather_code
|
||||
except Exception:
|
||||
wcode = 900 # tornado
|
||||
temp = -273.0
|
||||
img = Image.new('1', (128, 64), color=255)
|
||||
imgdraw = ImageDraw.Draw(img)
|
||||
imgdraw.text((0, 0), self.wcode_to_unicode[wcode], font=self.weatherfont, fill=0)
|
||||
|
Loading…
Reference in New Issue
Block a user