This commit is contained in:
parent
7e8ad576c4
commit
c7f1752fad
2 changed files with 67 additions and 0 deletions
|
@ -8,6 +8,7 @@ from geventwebsocket.websocket import WebSocket
|
||||||
from buba.animations.dbf import DBFAnimation
|
from buba.animations.dbf import DBFAnimation
|
||||||
from buba.animations.icalevents import IcalEvents
|
from buba.animations.icalevents import IcalEvents
|
||||||
from buba.animations.snake import SnakeAnimation
|
from buba.animations.snake import SnakeAnimation
|
||||||
|
from buba.animations.spaceapi import Spaceapi
|
||||||
from buba.animations.time import BubaTime
|
from buba.animations.time import BubaTime
|
||||||
from buba.appconfig import AppConfig
|
from buba.appconfig import AppConfig
|
||||||
from buba.bubaanimator import BubaAnimator
|
from buba.bubaanimator import BubaAnimator
|
||||||
|
@ -34,6 +35,7 @@ animator.add(DBFAnimation, ds100="AHST", station="Holstenstraße")
|
||||||
animator.add(DBFAnimation, ds100="AHS", station="Altona", count=9)
|
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",
|
animator.add(IcalEvents, url="https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/QJAdExziSnNJEz5g?export",
|
||||||
title="CCCHH Events")
|
title="CCCHH Events")
|
||||||
|
animator.add(Spaceapi, "https://spaceapi.hamburg.ccc.de", "CCCHH")
|
||||||
animator.add(SnakeAnimation)
|
animator.add(SnakeAnimation)
|
||||||
|
|
||||||
@app.route("/static/<filepath>")
|
@app.route("/static/<filepath>")
|
||||||
|
|
65
buba/animations/spaceapi.py
Normal file
65
buba/animations/spaceapi.py
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
from threading import Thread
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from buba.bubaanimator import BubaAnimation
|
||||||
|
from buba.bubacmd import BubaCmd
|
||||||
|
|
||||||
|
|
||||||
|
class Spaceapi(BubaAnimation):
|
||||||
|
def __init__(self, buba, url, title):
|
||||||
|
super().__init__(buba)
|
||||||
|
self.url = url
|
||||||
|
self.title = title
|
||||||
|
self.data = {}
|
||||||
|
self.load()
|
||||||
|
Thread(target=self.update, daemon=True).start()
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
res = requests.get(self.url)
|
||||||
|
self.data = json.loads(res.text)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
while True:
|
||||||
|
self.load()
|
||||||
|
sleep(60)
|
||||||
|
|
||||||
|
def humanize(self, dt):
|
||||||
|
td = dt - datetime.now().astimezone()
|
||||||
|
self.log.debug(f"dt {dt}, td {td}, {td.total_seconds()}")
|
||||||
|
if td.total_seconds() > -60:
|
||||||
|
return "just now"
|
||||||
|
if td.total_seconds() > -3600:
|
||||||
|
return f"for {-int(td.total_seconds()/60)} minutes"
|
||||||
|
if td.total_seconds() >- 86400:
|
||||||
|
return f"for {-int(td.total_seconds()/3600)} hours"
|
||||||
|
return dt.strftime("since %y-%m-%d %H:%M")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
open = "open" if self.data["state"]["open"] else "closed"
|
||||||
|
since = datetime.fromtimestamp(self.data["state"]["lastchange"]).astimezone()
|
||||||
|
temp = int(self.data["sensors"]["temperature"][0]["value"])
|
||||||
|
hum = int(self.data["sensors"]["humidity"][0]["value"])
|
||||||
|
printers = {}
|
||||||
|
for p in self.data["sensors"]["ext_3d_printer_busy_state"]:
|
||||||
|
printers[p["name"]] = {
|
||||||
|
"busy": p["value"] != 0,
|
||||||
|
}
|
||||||
|
for p in self.data["sensors"]["ext_3d_printer_minutes_remaining"]:
|
||||||
|
printers[p["name"]]["remaining"] = p["value"]
|
||||||
|
printstatus = []
|
||||||
|
for n, p in printers.items():
|
||||||
|
if p["busy"]:
|
||||||
|
printstatus.append(f"{n} remaining {p['remaining']}")
|
||||||
|
else:
|
||||||
|
printstatus.append(f"{n} idle")
|
||||||
|
|
||||||
|
self.buba.text(page=0, row=0, col_start=0, col_end=119, text=f"CCCHH {open} {self.humanize(since)}", align=BubaCmd.ALIGN_LEFT)
|
||||||
|
self.buba.text(page=0, row=1, col_start=0, col_end=119, text=f"Outside: {temp}°C at {hum}% rel.hum.", align=BubaCmd.ALIGN_LEFT)
|
||||||
|
self.buba.text(page=0, row=2, col_start=0, col_end=119, text=", ".join(printstatus), align=BubaCmd.ALIGN_LEFT)
|
||||||
|
|
||||||
|
sleep(10)
|
Loading…
Add table
Add a link
Reference in a new issue