ical: Distinguish local and non-local events
This commit is contained in:
parent
ae83da28ed
commit
15ba4ae0ed
2
main.py
2
main.py
@ -67,7 +67,7 @@ def main(only_on_coming_evt=False):
|
|||||||
image.paste(cal, (0, 250))
|
image.paste(cal, (0, 250))
|
||||||
|
|
||||||
occuped_space = 0
|
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:
|
if evt_coming:
|
||||||
from modules.ratp import RATPNextStopModule
|
from modules.ratp import RATPNextStopModule
|
||||||
nstops = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire", "M7/porte+d'italie"], int(480/1.6), 275)
|
nstops = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire", "M7/porte+d'italie"], int(480/1.6), 275)
|
||||||
|
@ -31,9 +31,11 @@ class IcalModule:
|
|||||||
with urllib.request.urlopen(cal) as c:
|
with urllib.request.urlopen(cal) as c:
|
||||||
with open(cache_file, 'wb') as fd:
|
with open(cache_file, 'wb') as fd:
|
||||||
fd.write(c.read())
|
fd.write(c.read())
|
||||||
except ConnectionResetError:
|
except ConnectionResetError as e:
|
||||||
|
print(e)
|
||||||
pass
|
pass
|
||||||
except urllib.error.URLError:
|
except urllib.error.URLError as e:
|
||||||
|
print(e)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with open(cache_file) as c:
|
with open(cache_file) as c:
|
||||||
@ -172,6 +174,37 @@ class IcalModule:
|
|||||||
return now < start and start < coming
|
return now < start and start < coming
|
||||||
return False
|
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):
|
def draw_module(self, config, width, height, line_height=19):
|
||||||
now = datetime.now(tz=pytz.timezone('Europe/Paris'))
|
now = datetime.now(tz=pytz.timezone('Europe/Paris'))
|
||||||
events = self.get_events(config, now + timedelta(weeks=1), now)
|
events = self.get_events(config, now + timedelta(weeks=1), now)
|
||||||
|
Loading…
Reference in New Issue
Block a user