More fixes #2
1 changed files with 78 additions and 49 deletions
123
src/main.py
123
src/main.py
|
|
@ -2,12 +2,13 @@
|
||||||
import json
|
import json
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import sleep, time
|
from time import sleep
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from pywinauto import Desktop
|
from pywinauto import Desktop
|
||||||
|
from pywinauto.controls.hwndwrapper import InvalidWindowHandle
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.chrome.options import Options
|
from selenium.webdriver.chrome.options import Options
|
||||||
|
|
||||||
|
|
@ -34,6 +35,16 @@ class Cache:
|
||||||
event: List[SalmonRunEvent]
|
event: List[SalmonRunEvent]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class RenderType:
|
||||||
|
HUDDLE = "HUDDLE"
|
||||||
|
OBS_PAUSED = "OBS_PAUSED"
|
||||||
|
OBS_RECORDING = "OBS_RECORDING"
|
||||||
|
OBS_STREAMING = "OBS_STREAMING"
|
||||||
|
SPLATOON = "SPLATOON"
|
||||||
|
ZOOM = "ZOOM"
|
||||||
|
|
||||||
|
|
||||||
CACHED: Cache = None
|
CACHED: Cache = None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,72 +104,90 @@ def get_salmon_run_data() -> List[SalmonRunEvent]:
|
||||||
def main():
|
def main():
|
||||||
"""The main run function of the application"""
|
"""The main run function of the application"""
|
||||||
desktop = Desktop()
|
desktop = Desktop()
|
||||||
showing_sploon = False
|
rendering = ""
|
||||||
rotation_time = 15 # the amount of time between tidbyt app rotations
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
start_time = time()
|
windows = list(
|
||||||
windows = []
|
filter(
|
||||||
for window in desktop.windows():
|
lambda x: x, # Filter out empty vals
|
||||||
try:
|
[w.window_text() for w in desktop.windows()],
|
||||||
txt = window.window_text()
|
)
|
||||||
if txt:
|
)
|
||||||
windows.append(txt)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
proc_time = time() - start_time
|
huddle_windows = list(filter(lambda x: "huddle" in x.lower(), windows))
|
||||||
huddle_windows = list(filter(lambda x: "Huddle" in x, windows))
|
obs_windows = list(filter(lambda x: "obs" in x.lower(), windows))
|
||||||
|
|
||||||
if "Zoom Meeting" in windows:
|
if "Zoom Meeting" in windows:
|
||||||
showing_sploon = False
|
if rendering != RenderType.ZOOM:
|
||||||
pixlet.display(rel_to_abspath("../zoom/meeting.webp"), installation_id="status")
|
pixlet.display(
|
||||||
sleep(max(0, rotation_time-proc_time))
|
rel_to_abspath("../zoom/meeting.webp"),
|
||||||
if huddle_windows:
|
installation_id="status",
|
||||||
showing_sploon = False
|
)
|
||||||
pixlet.display(rel_to_abspath("../slack/huddle.webp"), installation_id="status")
|
rendering = RenderType.ZOOM
|
||||||
sleep(max(0, rotation_time-proc_time))
|
elif huddle_windows:
|
||||||
elif "obs64" in windows:
|
if rendering != RenderType.HUDDLE:
|
||||||
showing_sploon = False
|
pixlet.display(
|
||||||
|
rel_to_abspath("../slack/huddle.webp"),
|
||||||
|
installation_id="status",
|
||||||
|
)
|
||||||
|
rendering = RenderType.HUDDLE
|
||||||
|
elif obs_windows:
|
||||||
with open(
|
with open(
|
||||||
rel_to_abspath("../status"), "r", encoding="utf-8"
|
rel_to_abspath("../status"), "r", encoding="utf-8"
|
||||||
) as file_handle:
|
) as file_handle:
|
||||||
data = json.loads(file_handle.read())
|
data = json.loads(file_handle.read())
|
||||||
if data["STREAMING"]:
|
if data["STREAMING"]:
|
||||||
pixlet.display(rel_to_abspath("../streaming/active.webp"), installation_id="status")
|
if rendering != RenderType.OBS_STREAMING:
|
||||||
|
pixlet.display(
|
||||||
|
rel_to_abspath("../streaming/active.webp"),
|
||||||
|
installation_id="status",
|
||||||
|
)
|
||||||
|
rendering = RenderType.OBS_STREAMING
|
||||||
elif data["RECORDING"]:
|
elif data["RECORDING"]:
|
||||||
pixlet.display(rel_to_abspath("../recording/active.webp"), installation_id="status")
|
if rendering != RenderType.OBS_RECORDING:
|
||||||
|
pixlet.display(
|
||||||
|
rel_to_abspath("../recording/active.webp"),
|
||||||
|
installation_id="status",
|
||||||
|
)
|
||||||
|
rendering = RenderType.OBS_RECORDING
|
||||||
else:
|
else:
|
||||||
pixlet.display(rel_to_abspath("../recording/paused.webp"), installation_id="status")
|
if rendering != RenderType.OBS_PAUSED:
|
||||||
sleep(max(0, rotation_time-proc_time))
|
pixlet.display(
|
||||||
|
rel_to_abspath("../recording/paused.webp"),
|
||||||
|
installation_id="status",
|
||||||
|
)
|
||||||
|
rendering = RenderType.OBS_PAUSED
|
||||||
else:
|
else:
|
||||||
# Only re-render a .star file if the cache should have expired or we hadn't rendered one yet
|
# Only re-render a .star file if the cache should have expired or we hadn't rendered one yet
|
||||||
if not showing_sploon or (
|
if not CACHED or (
|
||||||
CACHED and CACHED.last_update.date() != datetime.now().date()
|
CACHED and CACHED.last_update.date() != datetime.now().date()
|
||||||
): # prevents overworking
|
): # prevents overworking
|
||||||
salmon_run = get_salmon_run_data()[0]
|
if rendering != RenderType.SPLATOON:
|
||||||
|
salmon_run = get_salmon_run_data()[0]
|
||||||
|
|
||||||
render_file = rel_to_abspath("../templates/rendered.star")
|
render_file = rel_to_abspath("../templates/rendered.star")
|
||||||
pixlet.update_template(
|
pixlet.update_template(
|
||||||
rel_to_abspath("../templates/splatoon.star"),
|
rel_to_abspath("../templates/splatoon.star"),
|
||||||
render_file,
|
render_file,
|
||||||
{
|
{
|
||||||
"<IMAGE>": loadout_to_b64(salmon_run.loadout),
|
"<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'}",
|
"<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'}",
|
"<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,
|
"<STAGE>": salmon_run.stage_name,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
pixlet.render(render_file)
|
pixlet.render(render_file)
|
||||||
pixlet.display(
|
pixlet.display(
|
||||||
render_file.replace(".star", ".webp"),
|
render_file.replace(".star", ".webp"),
|
||||||
installation_id="status",
|
installation_id="status",
|
||||||
)
|
)
|
||||||
showing_sploon = True
|
rendering = RenderType.SPLATOON
|
||||||
sleep(5)
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
|
except InvalidWindowHandle:
|
||||||
|
continue
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue