ical: Distinguish local and non-local events

This commit is contained in:
nemunaire 2022-09-19 12:27:22 +02:00
parent ae83da28ed
commit 15ba4ae0ed
2 changed files with 36 additions and 3 deletions

View File

@ -67,7 +67,7 @@ def main(only_on_coming_evt=False):
image.paste(cal, (0, 250))
occuped_space = 0
evt_coming = ical.event_coming(config)
evt_coming = ical.non_local_event_coming(config) or ical.local_event_ending(config)
if evt_coming:
from modules.ratp import RATPNextStopModule
nstops = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire", "M7/porte+d'italie"], int(480/1.6), 275)

View File

@ -31,9 +31,11 @@ class IcalModule:
with urllib.request.urlopen(cal) as c:
with open(cache_file, 'wb') as fd:
fd.write(c.read())
except ConnectionResetError:
except ConnectionResetError as e:
print(e)
pass
except urllib.error.URLError:
except urllib.error.URLError as e:
print(e)
pass
with open(cache_file) as c:
@ -172,6 +174,37 @@ class IcalModule:
return now < start and start < coming
return False
def non_local_event_coming(self, config):
now = datetime.now(tz=pytz.timezone('Europe/Paris'))
coming = datetime.now(tz=pytz.timezone('Europe/Paris')) + timedelta(minutes=self.delayed_departure)
for evt in self.get_events(config):
if "location" in evt and (
evt["location"].lower().startswith("http") or
evt["location"].lower().startswith("ici") or
evt["location"].lower().endswith("gentilly") or
evt["location"].lower().endswith("gentilly, france")
):
continue
# Looking only the first event
start = evt["start"]
return now < start and start < coming
return False
def local_event_ending(self, config):
now = datetime.now(tz=pytz.timezone('Europe/Paris')) + timedelta(minutes=self.delayed_departure/3)
coming = datetime.now(tz=pytz.timezone('Europe/Paris')) + timedelta(minutes=self.delayed_departure/3)
for evt in self.get_events(config):
if not("location" in evt and evt["location"].lower().startswith("ici")):
continue
# Looking only the first event
end = evt["end"]
return now < end and end < coming
return False
def draw_module(self, config, width, height, line_height=19):
now = datetime.now(tz=pytz.timezone('Europe/Paris'))
events = self.get_events(config, now + timedelta(weeks=1), now)