Use multiple pages, fix timezone
All checks were successful
docker-image / docker (push) Successful in 9m52s

This commit is contained in:
Stefan Bethke 2025-06-02 22:10:54 +02:00
commit bbf1ae0484
4 changed files with 38 additions and 23 deletions

View file

@ -30,9 +30,9 @@ websocket_clients = WebSocketClients()
buba = BubaCmd(config.serial, websocket_clients.send)
animator = BubaAnimator(buba)
# animator.add(BubaCharset) #, single=12)
animator.add(BubaTime)
animator.add(DBFAnimation, ds100="AHST", station="Holstenstraße")
animator.add(DBFAnimation, ds100="AHS", station="Altona", count=9)
# animator.add(BubaTime)
# animator.add(DBFAnimation, ds100="AHST", station="Holstenstraße")
# animator.add(DBFAnimation, ds100="AHS", station="Altona", count=9)
animator.add(IcalEvents, url="https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/QJAdExziSnNJEz5g?export", title="CCCHH Events")
@app.route("/static/<filepath>")

View file

@ -4,7 +4,6 @@ Pull departure info from https://trains.xatlabs.com and display.
See also https://github.com/derf/db-fakedisplay/blob/main/README.md
"""
import datetime
from itertools import islice
from threading import Thread
from time import sleep
@ -95,11 +94,6 @@ class DBFAnimation(BubaAnimation):
train = train.replace(" ", "")
return train
@staticmethod
def chunk(it, size):
it = iter(it)
return iter(lambda: tuple(islice(it, size)), ())
def run(self):
all = self.trains[:self.count]
all_len = int((len(all)+1)/3)

View file

@ -1,9 +1,12 @@
import os
from datetime import timedelta, datetime
from threading import Thread
from time import sleep
from buba.bubaanimator import BubaAnimation
import icalevents.icalevents
from pytz import timezone
from buba.bubaanimator import BubaAnimation
from buba.bubacmd import BubaCmd
@ -12,26 +15,38 @@ class IcalEvents(BubaAnimation):
super().__init__(buba)
self.url = url
self.title = title
self.events = icalevents.icalevents.events(url)
self.log.debug(f"Events loaded {len(self.events)}")
self.events = []
Thread(target=self.update, daemon=True).start()
def __repr__(self):
return f"<{type(self).__name__}, {self.url}>"
def update(self):
tz = timezone(os.getenv("TZ", "Europe/Berlin"))
events = icalevents.icalevents.events(self.url, sort=True)
for event in events:
event.start = event.start.astimezone(tz)
self.events = events
sleep(600)
@staticmethod
def ellipsis(text, max=28):
if len(text) > max:
text = text[:max-3] + "..."
text = text[:max - 3] + "..."
return text
def run(self):
for (page, events) in enumerate(self.chunk(self.events, 3)):
if len(self.events) > 3:
self.buba.text(page=0, row=0, col_start=0, col_end=119,
text=f"{self.title} ({page + 1}/{int(len(self.events) / 3)})", align=BubaCmd.ALIGN_LEFT)
else:
self.buba.text(page=0, row=0, col_start=0, col_end=119, text=self.title, align=BubaCmd.ALIGN_LEFT)
for (i, event) in enumerate(self.events[0:3]):
if event.start - datetime.now(event.start.tzinfo) < timedelta(hours=20):
for (i, event) in enumerate(events):
if event.start - datetime.now(event.start.tzinfo) < timedelta(hours=24):
when = event.start.strftime("%H:%M")
else:
when = event.start.strftime("%d.%m.")
self.log.info(f"event '{self.ellipsis(event.summary)} at {when}")
self.buba.text(page=0, row=i + 1, col_start=0, col_end=104, text=self.ellipsis(event.summary))
self.buba.text(page=0, row=i + 1, col_start=105, col_end=119,
text=when, align=BubaCmd.ALIGN_RIGHT)

View file

@ -1,4 +1,5 @@
import logging
from itertools import islice
from threading import Thread
from time import sleep
@ -11,6 +12,11 @@ class BubaAnimation:
self.buba = buba
pass
@staticmethod
def chunk(it, size):
it = iter(it)
return iter(lambda: tuple(islice(it, size)), ())
def run(self):
pass