Dynamic splatoon screen
This commit is contained in:
parent
8cfa17cadc
commit
c760d7d6ff
11 changed files with 327 additions and 311 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -5,3 +5,5 @@ start.bat
|
||||||
status
|
status
|
||||||
test.py
|
test.py
|
||||||
geckodriver.log
|
geckodriver.log
|
||||||
|
weapons
|
||||||
|
templates/rendered*
|
||||||
|
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
STARTUP_INFO = subprocess.STARTUPINFO()
|
|
||||||
STARTUP_INFO.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
||||||
|
|
||||||
TEMPLATE = '''
|
|
||||||
load("render.star", "render")
|
|
||||||
load("encoding/base64.star", "base64")
|
|
||||||
|
|
||||||
def main():
|
|
||||||
return render.Root(
|
|
||||||
max_age=60,
|
|
||||||
delay=125,
|
|
||||||
child=render.Marquee(
|
|
||||||
height=32,
|
|
||||||
offset_start = 32,
|
|
||||||
offset_end = 32,
|
|
||||||
scroll_direction="vertical",
|
|
||||||
child=render.WrappedText("""<TEMP>""", width=60)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def _abp(path: str) -> str:
|
|
||||||
path_root = os.path.realpath(__file__).replace("dynamic_star.py", "")
|
|
||||||
return f"{path_root}\\{path}"
|
|
||||||
|
|
||||||
|
|
||||||
def _render():
|
|
||||||
subprocess.Popen(
|
|
||||||
[_abp("pixlet.exe"), "render", _abp("splatoon_dynamic.star")],
|
|
||||||
startupinfo=STARTUP_INFO,
|
|
||||||
).wait()
|
|
||||||
|
|
||||||
|
|
||||||
def _display():
|
|
||||||
with open(_abp("device_id"), "r", encoding="utf-8") as file_handle:
|
|
||||||
device_id = file_handle.read()
|
|
||||||
subprocess.Popen(
|
|
||||||
[
|
|
||||||
_abp("pixlet.exe"),
|
|
||||||
"push",
|
|
||||||
"--installation-id",
|
|
||||||
"SalmonRun",
|
|
||||||
device_id,
|
|
||||||
_abp("splatoon_dynamic.webp"),
|
|
||||||
],
|
|
||||||
startupinfo=STARTUP_INFO,
|
|
||||||
).wait()
|
|
||||||
|
|
||||||
|
|
||||||
def show_text(text: str) -> None:
|
|
||||||
with open(_abp("splatoon_dynamic.star"), "w", encoding="utf-8") as file_handle:
|
|
||||||
file_handle.write(TEMPLATE.replace("<TEMP>", text))
|
|
||||||
_render()
|
|
||||||
_display()
|
|
||||||
139
main.py
139
main.py
|
|
@ -1,139 +0,0 @@
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
from dynamic_star import show_text
|
|
||||||
from time import sleep
|
|
||||||
from typing import List
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from pywinauto import Desktop
|
|
||||||
from selenium import webdriver
|
|
||||||
from selenium.webdriver.firefox.options import Options
|
|
||||||
|
|
||||||
path_root = os.path.realpath(__file__).replace("main.py", "")
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class SalmonRunEvent:
|
|
||||||
date: str
|
|
||||||
stage_name: str
|
|
||||||
loadout: str
|
|
||||||
rewards: str
|
|
||||||
|
|
||||||
|
|
||||||
def abp(path: str) -> str:
|
|
||||||
return f"{path_root}\\{path}"
|
|
||||||
|
|
||||||
|
|
||||||
def display(file_name: str):
|
|
||||||
with open(abp("device_id"), "r", encoding="utf-8") as file_handle:
|
|
||||||
device_id = file_handle.read()
|
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
||||||
subprocess.Popen(
|
|
||||||
[abp("pixlet.exe"), "push", device_id, abp(file_name)], startupinfo=startupinfo
|
|
||||||
).wait()
|
|
||||||
|
|
||||||
|
|
||||||
def get_salmon_run_data() -> List[SalmonRunEvent]:
|
|
||||||
"""Scrapes salmon run data"""
|
|
||||||
options = Options()
|
|
||||||
options.add_argument("--headless")
|
|
||||||
|
|
||||||
driver = webdriver.Firefox(options=options)
|
|
||||||
driver.get("https://splatoon.oatmealdome.me/three/salmon-run")
|
|
||||||
|
|
||||||
page_source = driver.page_source
|
|
||||||
page_source = BeautifulSoup(page_source, features="html.parser")
|
|
||||||
main_entry = page_source.body.find("main", attrs={"role": "main"}).find(
|
|
||||||
"div", attrs={"class": "d-grid gap-3"}
|
|
||||||
)
|
|
||||||
|
|
||||||
# The row where the datetime is shown when the evt. will occur
|
|
||||||
times = [
|
|
||||||
x.text.strip()
|
|
||||||
for x in main_entry.find_all("div", attrs={"class": "d-flex flex-row"})
|
|
||||||
]
|
|
||||||
# The row where the actual Salmon Run loadout & reward is
|
|
||||||
events: List[BeautifulSoup] = main_entry.find_all(
|
|
||||||
"div", attrs={"class": "bg-salmon-run"}
|
|
||||||
)
|
|
||||||
|
|
||||||
data = []
|
|
||||||
|
|
||||||
for idx, evt in enumerate(events):
|
|
||||||
time = times[idx]
|
|
||||||
stage_name = evt.find("span", attrs={"class": "text-stage-name"}).text
|
|
||||||
|
|
||||||
event_root = evt.find("div", attrs={"class": "col d-flex flex-column"})
|
|
||||||
|
|
||||||
# Get the photos of the loadout, then lean on the `title` attr
|
|
||||||
loadout_pic_els = event_root.find("div", attrs={"class": "row gx-2"}).find_all(
|
|
||||||
"picture"
|
|
||||||
)
|
|
||||||
loadout = [x.find("img").attrs["title"] for x in loadout_pic_els]
|
|
||||||
|
|
||||||
# Get the photos of the reward, then lean on the `title` attr
|
|
||||||
reward_pic_els = event_root.find(
|
|
||||||
"div", attrs={"class": "row mt-3 gx-2"}
|
|
||||||
).find_all("picture")
|
|
||||||
rewards = [x.find("img").attrs["title"] for x in reward_pic_els]
|
|
||||||
|
|
||||||
data.append(
|
|
||||||
SalmonRunEvent(time, stage_name, ", ".join(loadout), ", ".join(rewards))
|
|
||||||
)
|
|
||||||
|
|
||||||
driver.close()
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
desktop = Desktop()
|
|
||||||
|
|
||||||
salmon_runs = get_salmon_run_data()
|
|
||||||
text = []
|
|
||||||
for event in salmon_runs:
|
|
||||||
# Display the event for a bit, then sleep
|
|
||||||
text.append(
|
|
||||||
f"""{event.date}\n\nSTAGE:\n{event.stage_name}\n\nLOADOUT:\n{event.loadout}\n\nREWARD(S):\n{event.rewards}"""
|
|
||||||
)
|
|
||||||
# show_text(
|
|
||||||
# f"{event.date}: {event.stage_name}",
|
|
||||||
# f"Loadout: {event.loadout} | Rewards: {event.rewards}",
|
|
||||||
# )
|
|
||||||
# sleep(60)
|
|
||||||
|
|
||||||
show_text("\n-------\n\n".join(text))
|
|
||||||
return
|
|
||||||
|
|
||||||
# print(json.dumps(get_salmon_run_data(), indent=2))
|
|
||||||
# return
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
windows = list(
|
|
||||||
filter(lambda x: x, [w.window_text() for w in desktop.windows()])
|
|
||||||
)
|
|
||||||
|
|
||||||
if "Zoom Meeting" in windows:
|
|
||||||
display("zoom/meeting.webp")
|
|
||||||
sleep(16)
|
|
||||||
elif "obs64" in windows:
|
|
||||||
with open(abp("status"), "r", encoding="utf-8") as file_handle:
|
|
||||||
data = json.loads(file_handle.read())
|
|
||||||
if data["STREAMING"]:
|
|
||||||
display("streaming/active.webp")
|
|
||||||
sleep(10)
|
|
||||||
elif data["RECORDING"]:
|
|
||||||
display("recording/active.webp")
|
|
||||||
sleep(12)
|
|
||||||
else:
|
|
||||||
display("recording/paused.webp")
|
|
||||||
sleep(10)
|
|
||||||
else:
|
|
||||||
sleep(1)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Quitting...")
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
main()
|
|
||||||
34
out.star
Normal file
34
out.star
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,73 +0,0 @@
|
||||||
|
|
||||||
load("render.star", "render")
|
|
||||||
load("encoding/base64.star", "base64")
|
|
||||||
|
|
||||||
def main():
|
|
||||||
return render.Root(
|
|
||||||
max_age=60,
|
|
||||||
delay=125,
|
|
||||||
child=render.Marquee(
|
|
||||||
height=32,
|
|
||||||
offset_start = 32,
|
|
||||||
offset_end = 32,
|
|
||||||
scroll_direction="vertical",
|
|
||||||
child=render.WrappedText("""Nov 5, 2022, 11:00 AM - Nov 7, 2022, 2:00 AM
|
|
||||||
|
|
||||||
STAGE:
|
|
||||||
Spawning Grounds
|
|
||||||
|
|
||||||
LOADOUT:
|
|
||||||
Sploosh-o-matic, Luna Blaster, Undercover Brella, Splat Charger
|
|
||||||
|
|
||||||
REWARD(S):
|
|
||||||
Brain Strainer
|
|
||||||
-------
|
|
||||||
|
|
||||||
Nov 7, 2022, 2:00 AM - Nov 8, 2022, 6:00 PM
|
|
||||||
|
|
||||||
STAGE:
|
|
||||||
Sockeye Station
|
|
||||||
|
|
||||||
LOADOUT:
|
|
||||||
Splat Roller, Dualie Squelchers, Nautilus 47, Heavy Splatling
|
|
||||||
|
|
||||||
REWARD(S):
|
|
||||||
Brain Strainer
|
|
||||||
-------
|
|
||||||
|
|
||||||
Nov 8, 2022, 6:00 PM - Nov 10, 2022, 10:00 AM
|
|
||||||
|
|
||||||
STAGE:
|
|
||||||
Gone Fission Hydroplant
|
|
||||||
|
|
||||||
LOADOUT:
|
|
||||||
Tri-Slosher, L-3 Nozzlenose, Splat Brella, .96 Gal
|
|
||||||
|
|
||||||
REWARD(S):
|
|
||||||
Brain Strainer
|
|
||||||
-------
|
|
||||||
|
|
||||||
Nov 10, 2022, 10:00 AM - Nov 12, 2022, 2:00 AM
|
|
||||||
|
|
||||||
STAGE:
|
|
||||||
Spawning Grounds
|
|
||||||
|
|
||||||
LOADOUT:
|
|
||||||
Splattershot Jr., Sloshing Machine, Range Blaster, Goo Tuber
|
|
||||||
|
|
||||||
REWARD(S):
|
|
||||||
Brain Strainer
|
|
||||||
-------
|
|
||||||
|
|
||||||
Nov 12, 2022, 2:00 AM - Nov 13, 2022, 6:00 PM
|
|
||||||
|
|
||||||
STAGE:
|
|
||||||
Sockeye Station
|
|
||||||
|
|
||||||
LOADOUT:
|
|
||||||
Splat Dualies, Carbon Roller, Splattershot Pro, Splat Charger
|
|
||||||
|
|
||||||
REWARD(S):
|
|
||||||
Brain Strainer""", width=60)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 91 KiB |
|
|
@ -1,15 +1,16 @@
|
||||||
|
"""General image magiks"""
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
from typing import List, Tuple
|
from typing import List
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from webptools import cwebp, dwebp, webpmux_animate
|
from webptools import dwebp
|
||||||
|
|
||||||
from util import rel_to_abspath
|
from util import rel_to_abspath
|
||||||
|
|
||||||
|
|
||||||
def download_image(link: str) -> Tuple[bool, str]:
|
def download_image(link: str) -> str:
|
||||||
"""Downloads an image via url only if it doesn't exist locally"""
|
"""Downloads an image via url only if it doesn't exist locally"""
|
||||||
out_dir = rel_to_abspath("../weapons").replace("\\", os.sep).replace("/", os.sep)
|
out_dir = rel_to_abspath("../weapons").replace("\\", os.sep).replace("/", os.sep)
|
||||||
file_name = link.split("/")[-1]
|
file_name = link.split("/")[-1]
|
||||||
|
|
@ -18,14 +19,12 @@ def download_image(link: str) -> Tuple[bool, str]:
|
||||||
if not os.path.exists(out_dir):
|
if not os.path.exists(out_dir):
|
||||||
os.mkdir(out_dir)
|
os.mkdir(out_dir)
|
||||||
|
|
||||||
existed = True
|
|
||||||
if not os.path.exists(full_path):
|
if not os.path.exists(full_path):
|
||||||
existed = False
|
|
||||||
img_data = requests.get(link).content
|
img_data = requests.get(link).content
|
||||||
with open(full_path, "wb") as handler:
|
with open(full_path, "wb") as handler:
|
||||||
handler.write(img_data)
|
handler.write(img_data)
|
||||||
|
|
||||||
return (existed, full_path)
|
return full_path
|
||||||
|
|
||||||
|
|
||||||
def loadout_to_b64(loadout: List[str]) -> str:
|
def loadout_to_b64(loadout: List[str]) -> str:
|
||||||
|
|
@ -35,40 +34,25 @@ def loadout_to_b64(loadout: List[str]) -> str:
|
||||||
Arguments:
|
Arguments:
|
||||||
loadout (List[str]): a list of URLs for each weapon
|
loadout (List[str]): a list of URLs for each weapon
|
||||||
"""
|
"""
|
||||||
inputs: List[str] = []
|
frames: List[Image.Image] = []
|
||||||
for img_url in loadout:
|
for img_url in loadout:
|
||||||
existed, path = download_image(img_url)
|
path = download_image(img_url)
|
||||||
if not existed: # Only resize if the image didn't already exist
|
# Convert webp to png
|
||||||
dwebp(input_image=path, output_image=f"{path}.png", option="-o")
|
dwebp(input_image=path, output_image=f"{path}.png", option="-o")
|
||||||
Image.open(f"{path}.png").resize((24, 24)).save(f"{path}.png")
|
frames.append(Image.open(path).resize((24, 24)))
|
||||||
cwebp(input_image=f"{path}.png", output_image=path, option="-q 100")
|
|
||||||
os.unlink(f"{path}.png")
|
|
||||||
inputs.append(f"{path} +1000+0+0+1")
|
|
||||||
|
|
||||||
webpmux_animate(
|
gif_path = rel_to_abspath("../temp.gif")
|
||||||
input_images=inputs,
|
frames[0].save(
|
||||||
output_image=rel_to_abspath("../temp.webp"),
|
gif_path,
|
||||||
loop="10",
|
format="GIF",
|
||||||
bgcolor="0,0,0,0",
|
append_images=frames[1:],
|
||||||
|
save_all=True,
|
||||||
|
duration=5000,
|
||||||
|
disposal=2,
|
||||||
|
loop=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
img = Image.open(rel_to_abspath("../temp.webp"))
|
with open(gif_path, "rb") as fh:
|
||||||
img.info.pop("background", None)
|
b64 = base64.b64encode(fh.read())
|
||||||
img.save(rel_to_abspath("../temp.gif"), "gif", save_all=True)
|
os.unlink(gif_path)
|
||||||
|
return b64.decode("utf-8")
|
||||||
with open(rel_to_abspath("../temp.gif"), "rb") as file_handle:
|
|
||||||
b64 = base64.b64encode(file_handle.read())
|
|
||||||
# os.unlink(rel_to_abspath("../temp.webp"))
|
|
||||||
return b64
|
|
||||||
|
|
||||||
|
|
||||||
print(
|
|
||||||
loadout_to_b64(
|
|
||||||
[
|
|
||||||
"https://splatoon.oatmealdome.me/img/weapon/thunder/Shooter_Short_00.webp",
|
|
||||||
"https://splatoon.oatmealdome.me/img/weapon/thunder/Blaster_Short_00.webp",
|
|
||||||
"https://splatoon.oatmealdome.me/img/weapon/thunder/Shelter_Compact_00.webp",
|
|
||||||
"https://splatoon.oatmealdome.me/img/weapon/thunder/Charger_Normal_00.webp",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
147
src/main.py
Normal file
147
src/main.py
Normal file
|
|
@ -0,0 +1,147 @@
|
||||||
|
import json
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime
|
||||||
|
from time import sleep
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import dateutil.parser
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from pywinauto import Desktop
|
||||||
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.firefox.options import Options
|
||||||
|
|
||||||
|
import pixlet
|
||||||
|
from images import loadout_to_b64
|
||||||
|
from util import rel_to_abspath
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class SalmonRunEvent:
|
||||||
|
"""Represents a GrizzCo Job"""
|
||||||
|
|
||||||
|
start: datetime
|
||||||
|
end: datetime
|
||||||
|
stage_name: str
|
||||||
|
loadout: List[str]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Cache:
|
||||||
|
"""Caching System"""
|
||||||
|
|
||||||
|
last_update: datetime
|
||||||
|
event: List[SalmonRunEvent]
|
||||||
|
|
||||||
|
|
||||||
|
CACHED: Cache = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_salmon_run_data() -> List[SalmonRunEvent]:
|
||||||
|
"""Scrapes salmon run data"""
|
||||||
|
global CACHED
|
||||||
|
if CACHED and CACHED.last_update.date == datetime.now().date:
|
||||||
|
return CACHED.event
|
||||||
|
|
||||||
|
options = Options()
|
||||||
|
options.add_argument("--headless")
|
||||||
|
driver = webdriver.Firefox(options=options)
|
||||||
|
driver.get("https://splatoon.oatmealdome.me/three/salmon-run")
|
||||||
|
|
||||||
|
main_el = driver.page_source
|
||||||
|
main_el = BeautifulSoup(main_el, features="html.parser")
|
||||||
|
main_el = main_el.body.find("main", attrs={"role": "main"}).find(
|
||||||
|
"div", attrs={"class": "d-grid gap-3"}
|
||||||
|
)
|
||||||
|
|
||||||
|
# The row where the datetime is shown when the evt. will occur
|
||||||
|
times: List[str] = [
|
||||||
|
x.text.strip()
|
||||||
|
for x in main_el.find_all("div", attrs={"class": "d-flex flex-row"})
|
||||||
|
]
|
||||||
|
# The row where the actual Salmon Run loadout & reward is
|
||||||
|
events: List[BeautifulSoup] = main_el.find_all(
|
||||||
|
"div", attrs={"class": "bg-salmon-run"}
|
||||||
|
)
|
||||||
|
|
||||||
|
data: List[SalmonRunEvent] = []
|
||||||
|
|
||||||
|
for idx, evt in enumerate(events):
|
||||||
|
start, end = times[idx].split(" - ")
|
||||||
|
start = dateutil.parser.parse(start)
|
||||||
|
end = dateutil.parser.parse(end)
|
||||||
|
stage_name = evt.find("span", attrs={"class": "text-stage-name"}).text
|
||||||
|
|
||||||
|
event_root = evt.find("div", attrs={"class": "col d-flex flex-column"})
|
||||||
|
|
||||||
|
# Get the photos of the loadout, then lean on the `title` attr
|
||||||
|
loadout = [
|
||||||
|
f"https://splatoon.oatmealdome.me/{x.find('img').attrs['src']}"
|
||||||
|
for x in event_root.find("div", attrs={"class": "row gx-2"}).find_all(
|
||||||
|
"picture"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
data.append(SalmonRunEvent(start, end, stage_name, loadout))
|
||||||
|
|
||||||
|
driver.close()
|
||||||
|
CACHED = Cache(last_update=datetime.now(), event=data)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""The main run function of the application"""
|
||||||
|
desktop = Desktop()
|
||||||
|
showing_sploon = False
|
||||||
|
rotation_time = 15 # the amount of time between tidbyt app rotations
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
windows = list(
|
||||||
|
filter(lambda x: x, [w.window_text() for w in desktop.windows()])
|
||||||
|
)
|
||||||
|
|
||||||
|
if "Zoom Meeting" in windows:
|
||||||
|
showing_sploon = False
|
||||||
|
pixlet.display(rel_to_abspath("../zoom/meeting.webp"))
|
||||||
|
sleep(rotation_time)
|
||||||
|
elif "obs64" in windows:
|
||||||
|
showing_sploon = False
|
||||||
|
with open(
|
||||||
|
rel_to_abspath("../status"), "r", encoding="utf-8"
|
||||||
|
) as file_handle:
|
||||||
|
data = json.loads(file_handle.read())
|
||||||
|
if data["STREAMING"]:
|
||||||
|
pixlet.display(rel_to_abspath("../streaming/active.webp"))
|
||||||
|
elif data["RECORDING"]:
|
||||||
|
pixlet.display(rel_to_abspath("../recording/active.webp"))
|
||||||
|
else:
|
||||||
|
pixlet.display(rel_to_abspath("../recording/paused.webp"))
|
||||||
|
sleep(rotation_time)
|
||||||
|
else:
|
||||||
|
if not showing_sploon: # prevents overworking
|
||||||
|
salmon_run = get_salmon_run_data()[0]
|
||||||
|
|
||||||
|
render_file = rel_to_abspath("../templates/rendered.star")
|
||||||
|
pixlet.update_template(
|
||||||
|
rel_to_abspath("../templates/splatoon.star"),
|
||||||
|
render_file,
|
||||||
|
{
|
||||||
|
"<IMAGE>": loadout_to_b64(salmon_run.loadout),
|
||||||
|
"<START_DATE>": f"{salmon_run.start.month}/{salmon_run.start.day} {salmon_run.start.hour%12}:{str(salmon_run.start.minute).zfill(2)} {'AM' if salmon_run.start.hour < 12 else 'PM'}",
|
||||||
|
"<END_DATE>": f"{salmon_run.end.month}/{salmon_run.end.day} {salmon_run.end.hour%12}:{str(salmon_run.end.minute).zfill(2)} {'AM' if salmon_run.end.hour < 12 else 'PM'}",
|
||||||
|
"<STAGE>": salmon_run.stage_name,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
pixlet.render(render_file)
|
||||||
|
pixlet.display(
|
||||||
|
render_file.replace(".star", ".webp"),
|
||||||
|
installation_id="SalmonRun",
|
||||||
|
)
|
||||||
|
showing_sploon = True
|
||||||
|
sleep(5)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
71
src/pixlet.py
Normal file
71
src/pixlet.py
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
"""
|
||||||
|
Python wrapper for Pixlet Operations
|
||||||
|
"""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
from util import rel_to_abspath
|
||||||
|
|
||||||
|
STARTUP_INFO = subprocess.STARTUPINFO()
|
||||||
|
STARTUP_INFO.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
|
|
||||||
|
|
||||||
|
def update_template(template_path: str, out_path: str, replacers: dict):
|
||||||
|
"""
|
||||||
|
Opens the template up at template_path, reads it in,
|
||||||
|
replaces all keys in replacers with their values
|
||||||
|
then writes it out with the same name in `./out`
|
||||||
|
Arguments:
|
||||||
|
template_path (str): the path of the template.star to load
|
||||||
|
out_path (str): where the output should be saved
|
||||||
|
replacers (dict): a Dict[str,str] whose keys are in the template,
|
||||||
|
and whose values will replace their keys in the template
|
||||||
|
"""
|
||||||
|
if not os.path.exists("../out"):
|
||||||
|
os.mkdir("../out")
|
||||||
|
with open(template_path, "r", encoding="utf-8") as file_handle:
|
||||||
|
data = file_handle.read()
|
||||||
|
for key in replacers:
|
||||||
|
data = data.replace(key, replacers[key])
|
||||||
|
with open(out_path, "w", encoding="utf-8") as file_handle:
|
||||||
|
file_handle.write(data)
|
||||||
|
|
||||||
|
|
||||||
|
def display(file_path: str, installation_id: str = None):
|
||||||
|
"""
|
||||||
|
Displays a file (by name) to the Tidbyt, reading the device id from `device_id`
|
||||||
|
"""
|
||||||
|
with open(rel_to_abspath("../device_id"), "r", encoding="utf-8") as file_handle:
|
||||||
|
device_id = file_handle.read()
|
||||||
|
if installation_id:
|
||||||
|
args = [
|
||||||
|
rel_to_abspath("../pixlet.exe"),
|
||||||
|
"push",
|
||||||
|
"--installation-id",
|
||||||
|
installation_id,
|
||||||
|
device_id,
|
||||||
|
file_path,
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
args = [
|
||||||
|
rel_to_abspath("../pixlet.exe"),
|
||||||
|
"push",
|
||||||
|
device_id,
|
||||||
|
file_path,
|
||||||
|
]
|
||||||
|
|
||||||
|
with subprocess.Popen(args, startupinfo=STARTUP_INFO) as process:
|
||||||
|
process.wait()
|
||||||
|
|
||||||
|
|
||||||
|
def render(file_path: str):
|
||||||
|
"""
|
||||||
|
Uses Pixlet to render a `.star` file to webp so that it can be pushed
|
||||||
|
Args:
|
||||||
|
file_path (str): the path (relative) to the file you want rendered
|
||||||
|
"""
|
||||||
|
with subprocess.Popen(
|
||||||
|
[rel_to_abspath("../pixlet.exe"), "render", file_path],
|
||||||
|
startupinfo=STARTUP_INFO,
|
||||||
|
) as process:
|
||||||
|
process.wait()
|
||||||
14
src/util.py
Normal file
14
src/util.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
"""
|
||||||
|
General utils for things - mostly file path resolution
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
path_root = os.path.realpath(__file__).replace("util.py", "")
|
||||||
|
|
||||||
|
|
||||||
|
def rel_to_abspath(path: str) -> str:
|
||||||
|
"""
|
||||||
|
Converts a local path (like '../thing' to the absolute path)
|
||||||
|
"""
|
||||||
|
return f"{path_root}{path}".replace("\\", os.sep).replace("/", os.sep)
|
||||||
34
templates/splatoon.star
Normal file
34
templates/splatoon.star
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
load("render.star", "render")
|
||||||
|
load("encoding/base64.star", "base64")
|
||||||
|
|
||||||
|
ICON = base64.decode("<IMAGE>")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
return render.Root(
|
||||||
|
delay=250,
|
||||||
|
child=render.Column(
|
||||||
|
expanded=True,
|
||||||
|
main_align="space_around",
|
||||||
|
cross_align="center",
|
||||||
|
children=[
|
||||||
|
render.Marquee(
|
||||||
|
width=60,
|
||||||
|
child=render.Text(
|
||||||
|
"<START_DATE> - <END_DATE>",
|
||||||
|
color="#66ded2",
|
||||||
|
font="tom-thumb",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
render.Marquee(
|
||||||
|
width=60,
|
||||||
|
child=render.Text(
|
||||||
|
"<STAGE>",
|
||||||
|
color="#fc9c66",
|
||||||
|
font="tom-thumb",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
render.Image(ICON),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue