Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'on_pi' property #95

Merged
merged 4 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion debug.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash
python3 index.py -o --port 8080 $@ | ./ledcat --geometry 96x32 show

python3.11 index.py -o --port 8080 $@ | ./ledcat --geometry 96x32 show
4 changes: 2 additions & 2 deletions states/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import abstractmethod
from os import environ
from shutil import which
from socket import gethostname
from typing import List

import httpx
Expand All @@ -19,7 +19,7 @@ class BaseState:
def __init__(self, stdout):
super().__init__()
self.killed = False
self.on_pi = which("rpi-update")
self.on_pi = gethostname() == "lichtkrant"
self.player_class = None
self.game_meta = None
self.font_path = "./static/fonts/NotoMono-Regular.ttf"
Expand Down
47 changes: 33 additions & 14 deletions states/djo/corvee.mod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from math import floor
from random import randint
from os import environ

import httpx
from PIL import Image, ImageDraw, ImageFont, ImageOps
Expand All @@ -16,11 +17,20 @@ class State(BaseState):

# get corvee dashboard data
async def get_names(self):
try:
response = await self.client.get("https://corvee.djoamersfoort.nl/api/v1/selected", timeout=5)
except httpx.RequestError:
return {}
return response.json()
if self.on_pi:
try:
response = await self.client.get(
"https://corvee.djoamersfoort.nl/api/v1/selected",
headers={"Authorization": f"Bearer {environ.get('API_TOKEN')}"},
timeout=5
)
except httpx.RequestError:
return {}
return response.json()
return {
"selected": ["Jan", "Henk", "Piet"],
"present": ["Jan", "Henk", "Piet", "Bert", "Gert"]
}

# module check function
async def check(self, _state):
Expand All @@ -34,7 +44,8 @@ async def run(self):
names = await self.get_names()
colors = [(randint(128, 255), randint(128, 255), randint(128, 255)) for _ in names["present"]]
scroll_y = 0
scroll_speed = 8
scroll_max_speed = 6
scroll_speed = scroll_max_speed
chosen = []
fonts = {
"noto8": ImageFont.truetype(self.font_path, size=8),
Expand Down Expand Up @@ -69,25 +80,33 @@ async def run(self):
if scroll_y > len(names["present"]) * 12:
scroll_y = 1

draw.rectangle([(0, 10), (95, 22)], fill=None, outline="cyan", width=1)
draw.rectangle([(0, 10), (95, 22)], fill=None, outline=(0, 128, 255), width=1)

if scroll_speed > 1 and elapsed % 1 < .05:
scroll_speed -= 1
if scroll_speed > 1 and elapsed % 1 < .017:
scroll_speed -= 0.5 if scroll_speed <= 3 else 1
elif scroll_speed == 1 and (scroll_y + 10) % 12 == 0:
center_index = floor((scroll_y + 10) / 12)
if center_index == len(names["present"]):
center_index = 0

centered = names["present"][center_index]
if centered in names["selected"]:
image = ImageOps.solarize(image, threshold=20)
draw.rectangle([(0, 10), (95, 22)], fill=None, outline=(255, 64, 0), width=1)
await self.output_image(image)

await asyncio.sleep(5)
image = ImageOps.solarize(image, threshold=-20)
image = ImageOps.solarize(image, threshold=30)
await self.output_image(image)

await asyncio.sleep(0.25)
image = ImageOps.solarize(image, threshold=-30)
await self.output_image(image)

names["selected"].remove(centered)
chosen.append(centered)
elapsed = 15
scroll_y = 0
scroll_speed = 8
scroll_speed = scroll_max_speed
else:
for i, name in enumerate(chosen):
draw.text((48, 5 + 11 * i), name, fill=colors[i], anchor="mm", font=fonts["noto11"])
Expand All @@ -97,5 +116,5 @@ async def run(self):
draw.rectangle([(89, y - 8), (94, y - 4)], fill="blue")

await self.output_image(image)
await asyncio.sleep(.05)
elapsed += .05
await asyncio.sleep(.017)
elapsed += .017
Loading