Add CCCHH events

Closes #5
This commit is contained in:
Stefan Bethke 2025-06-02 21:54:55 +02:00
commit 7f12a3bbd8
5 changed files with 120 additions and 3 deletions

View file

@ -5,6 +5,7 @@ from bottle_log import LoggingPlugin
from bottle_websocket import websocket, GeventWebSocketServer
from geventwebsocket.websocket import WebSocket
from buba.animations.icalevents import IcalEvents
from buba.appconfig import AppConfig
from buba.bubaanimator import BubaAnimator
from buba.animations.time import BubaTime
@ -32,7 +33,7 @@ animator = BubaAnimator(buba)
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>")
def server_static(filepath):

View file

@ -0,0 +1,38 @@
from datetime import timedelta, datetime
from time import sleep
from buba.bubaanimator import BubaAnimation
import icalevents.icalevents
from buba.bubacmd import BubaCmd
class IcalEvents(BubaAnimation):
def __init__(self, buba, url, title):
super().__init__(buba)
self.url = url
self.title = title
self.events = icalevents.icalevents.events(url)
self.log.debug(f"Events loaded {len(self.events)}")
def __repr__(self):
return f"<{type(self).__name__}, {self.url}>"
@staticmethod
def ellipsis(text, max=28):
if len(text) > max:
text = text[:max-3] + "..."
return text
def run(self):
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):
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)
sleep(10)

View file

@ -7,6 +7,7 @@ from buba.bubacmd import BubaCmd
class BubaAnimation:
def __init__(self, buba: BubaCmd):
self.log = logging.getLogger(type(self).__name__)
self.buba = buba
pass