Bugfixes for events
Switched from timezone-unaware (naive) objects to timezone-aware objects to correctly display event times. The timezone is fetched from the system itself. As a result, a new dependency (pytz) is now being used to set the timezone.
This commit is contained in:
parent
25a57c22bc
commit
f1d4b79dac
@ -19,6 +19,7 @@ import random
|
|||||||
import gc
|
import gc
|
||||||
import feedparser
|
import feedparser
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from pytz import timezone
|
||||||
|
|
||||||
from settings import *
|
from settings import *
|
||||||
from image_data import *
|
from image_data import *
|
||||||
@ -52,13 +53,20 @@ else:
|
|||||||
|
|
||||||
im_open = Image.open
|
im_open = Image.open
|
||||||
|
|
||||||
|
'''Get system timezone and set timezone accordingly'''
|
||||||
|
file = open('/etc/timezone','r')
|
||||||
|
lines = file.readlines()
|
||||||
|
system_tz = lines[0].rstrip()
|
||||||
|
local_tz = timezone(system_tz)
|
||||||
|
|
||||||
|
|
||||||
owm = pyowm.OWM(api_key)
|
owm = pyowm.OWM(api_key)
|
||||||
|
|
||||||
"""Main loop starts from here"""
|
"""Main loop starts from here"""
|
||||||
def main():
|
def main():
|
||||||
calibration_countdown = 'initial'
|
calibration_countdown = 'initial'
|
||||||
while True:
|
while True:
|
||||||
time = datetime.now()
|
time = datetime.now().replace(tzinfo=local_tz)
|
||||||
hour = int(time.strftime("%-H"))
|
hour = int(time.strftime("%-H"))
|
||||||
month = int(time.now().strftime('%-m'))
|
month = int(time.now().strftime('%-m'))
|
||||||
year = int(time.now().strftime('%Y'))
|
year = int(time.now().strftime('%Y'))
|
||||||
@ -320,8 +328,10 @@ def main():
|
|||||||
|
|
||||||
"""Create a time span using the events_max_range value (in days)
|
"""Create a time span using the events_max_range value (in days)
|
||||||
to filter events in that range"""
|
to filter events in that range"""
|
||||||
agenda_max_days = arrow.now().replace(days=+22)
|
|
||||||
calendar_max_days = arrow.now().replace(days=+int(events_max_range))
|
time_span_calendar = time + timedelta(days=int(events_max_range))
|
||||||
|
time_span_agenda = time + timedelta(days=22)
|
||||||
|
|
||||||
if internet_available() is True:
|
if internet_available() is True:
|
||||||
print('Internet connection test passed'+'\n')
|
print('Internet connection test passed'+'\n')
|
||||||
print('Fetching events from your calendar'+'\n')
|
print('Fetching events from your calendar'+'\n')
|
||||||
@ -335,14 +345,27 @@ def main():
|
|||||||
decode = decode[:beginAlarmIndex] + decode[endAlarmIndex+12:]
|
decode = decode[:beginAlarmIndex] + decode[endAlarmIndex+12:]
|
||||||
ical = Calendar(decode)
|
ical = Calendar(decode)
|
||||||
for events in ical.events:
|
for events in ical.events:
|
||||||
if events.begin.date().year == today.year and events.begin.date().month is today.month:
|
if events.begin.date().year == today.year and events.begin.date().month == today.month:
|
||||||
if int((events.begin).format('D')) not in events_this_month:
|
if int((events.begin).format('D')) not in events_this_month:
|
||||||
events_this_month.append(int((events.begin).format('D')))
|
events_this_month.append(int((events.begin).format('D')))
|
||||||
if middle_section is 'Agenda' and events in ical.timeline.included(now, agenda_max_days):
|
if middle_section is 'Agenda' and time <= events.end.datetime <= time_span_agenda:
|
||||||
upcoming.append(events)
|
upcoming.append(events)
|
||||||
if middle_section is 'Calendar' and events in ical.timeline.included(now, calendar_max_days):
|
if middle_section is 'Calendar' and time <= events.end.datetime <= time_span_calendar:
|
||||||
upcoming.append(events)
|
upcoming.append(events)
|
||||||
|
|
||||||
|
'''Fix some known bugs from ics.py'''
|
||||||
|
for events in upcoming:
|
||||||
|
if events.all_day and events.duration.days > 1:
|
||||||
|
events.end = events.end.replace(days=-2)
|
||||||
|
for i in range(1, events.duration.days):
|
||||||
|
cc = events.clone()
|
||||||
|
cc.begin = cc.begin.replace(days=+i)
|
||||||
|
upcoming.append(cc)
|
||||||
|
|
||||||
|
for events in upcoming:
|
||||||
|
if events.begin.format('HH:mm') == '00:00':
|
||||||
|
events.make_all_day()
|
||||||
|
|
||||||
def event_begins(elem):
|
def event_begins(elem):
|
||||||
return elem.begin
|
return elem.begin
|
||||||
|
|
||||||
@ -352,7 +375,6 @@ def main():
|
|||||||
print("Could not fetch events from your iCalendar.")
|
print("Could not fetch events from your iCalendar.")
|
||||||
print("Either the internet connection is too weak or we're offline.")
|
print("Either the internet connection is too weak or we're offline.")
|
||||||
|
|
||||||
|
|
||||||
if middle_section is 'Agenda':
|
if middle_section is 'Agenda':
|
||||||
"""For the agenda view, create a list containing dates and events of the next 22 days"""
|
"""For the agenda view, create a list containing dates and events of the next 22 days"""
|
||||||
if len(upcoming) is not 0:
|
if len(upcoming) is not 0:
|
||||||
@ -365,9 +387,10 @@ def main():
|
|||||||
for events in upcoming:
|
for events in upcoming:
|
||||||
if events.begin.date().day == date.day:
|
if events.begin.date().day == date.day:
|
||||||
if not events.all_day:
|
if not events.all_day:
|
||||||
agenda_list.append({'value':events.begin.format('HH:mm')+ ' '+ str(events.name), 'type':'timed_event'})
|
agenda_list.append({'value':events.begin.to(system_tz).format('HH:mm')+ ' '+ str(events.name), 'type':'timed_event'})
|
||||||
else:
|
else:
|
||||||
agenda_list.append({'value':events.name, 'type':'full_day_event'})
|
agenda_list.append({'value':events.name, 'type':'full_day_event'})
|
||||||
|
|
||||||
if bottom_section is not "":
|
if bottom_section is not "":
|
||||||
del agenda_list[16:]
|
del agenda_list[16:]
|
||||||
image.paste(seperator2, agenda_view_lines['line17'])
|
image.paste(seperator2, agenda_view_lines['line17'])
|
||||||
|
Loading…
Reference in New Issue
Block a user