X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=kiosk.py;h=c9f84e9b1755fead9c07b71baa2f8d45bc1f05af;hb=fe0774367d9ee7c7968dbe275cd1c8dfff38f12b;hp=13fb2c95e824abb9dd8ca2839e5fdcd66ac04b74;hpb=55bcd1ba1b9d481e0d0dc604932bcc0f7f4fa127;p=kiosk.git diff --git a/kiosk.py b/kiosk.py index 13fb2c9..c9f84e9 100755 --- a/kiosk.py +++ b/kiosk.py @@ -19,17 +19,19 @@ import numpy as np import pvporcupine import pytz -import bootstrap -import config -import datetime_utils +from pyutils import ( + bootstrap, + config, +) +from pyutils.datetimes import datetime_utils +from pyutils.files import file_utils -import constants +import kiosk_constants import file_writer import renderer_catalog import chooser import listen import trigger_catalog -import utils cfg = config.add_commandline_args( @@ -142,9 +144,9 @@ def process_command(command: str, page_history: List[str], page_chooser) -> str: break elif 'internal' in command: if 'render' in command: - page = constants.render_stats_pagename + page = kiosk_constants.render_stats_pagename else: - page = constants.render_stats_pagename + page = kiosk_constants.render_stats_pagename elif 'weather' in command: if 'telma' in command or 'cabin' in command: page = 'weather-telma_3_10800.html' @@ -222,8 +224,8 @@ def thread_change_current(command_queue: Queue) -> None: page_chooser = chooser.weighted_random_chooser_with_triggers( trigger_catalog.get_triggers(), [filter_news_during_dinnertime] ) - current_file = os.path.join(constants.pages_dir, "current.shtml") - emergency_file = os.path.join(constants.pages_dir, "reload_immediately.html") + current_file = os.path.join(kiosk_constants.pages_dir, "current.shtml") + emergency_file = os.path.join(kiosk_constants.pages_dir, "reload_immediately.html") # Main chooser loop while True: @@ -255,7 +257,7 @@ def thread_change_current(command_queue: Queue) -> None: if triggered: if page != page_history[0] or (swap_page_target - now) < 10.0: logger.info(f'chooser: An emergency page reload to {page} is needed at this time.') - swap_page_target = now + constants.emergency_refresh_period_sec + swap_page_target = now + kiosk_constants.emergency_refresh_period_sec # Set current.shtml to the right page. try: @@ -263,7 +265,7 @@ def thread_change_current(command_queue: Queue) -> None: emit( f, page, - override_refresh_sec = constants.emergency_refresh_period_sec, + override_refresh_sec = kiosk_constants.emergency_refresh_period_sec, command = command ) logger.debug(f'chooser: Wrote {current_file}.') @@ -288,7 +290,7 @@ def thread_change_current(command_queue: Queue) -> None: logger.info( f'chooser: Nominal choice of {page} as the next to show.' ) - swap_page_target = now + constants.refresh_period_sec + swap_page_target = now + kiosk_constants.refresh_period_sec try: with open(current_file, "w") as f: emit(f, page) @@ -331,9 +333,9 @@ def emit_wrapped(f, "Bellevue", "USA", "US/Pacific", 47.610, -122.201 ) s = sun(city.observer, date=now, tzinfo=pytz.timezone("US/Pacific")) - sunrise_mod = utils.minute_number(s["sunrise"].hour, s["sunrise"].minute) - sunset_mod = utils.minute_number(s["sunset"].hour, s["sunset"].minute) - now_mod = utils.minute_number(now.hour, now.minute) + sunrise_mod = datetime_utils.minute_number(s["sunrise"].hour, s["sunrise"].minute) + sunset_mod = datetime_utils.minute_number(s["sunset"].hour, s["sunset"].minute) + now_mod = datetime_utils.minute_number(now.hour, now.minute) if now_mod < sunrise_mod or now_mod > (sunset_mod + 45): return "E6B8B8" elif now_mod < (sunrise_mod + 45) or now_mod > (sunset_mod + 120): @@ -346,11 +348,11 @@ def emit_wrapped(f, return float(override_refresh_sec * 1000.0) now = datetime.now(tz=pytz.timezone("US/Pacific")) if now.hour < 6: - return float(constants.refresh_period_night_sec * 1000.0) + return float(kiosk_constants.refresh_period_night_sec * 1000.0) else: - return float(constants.refresh_period_sec * 1000.0) + return float(kiosk_constants.refresh_period_sec * 1000.0) - age = utils.describe_age_of_file_briefly(f"pages/{filename}") + age = file_utils.describe_file_ctime(f"pages/{filename}") bgcolor = pick_background_color() if command is None: pageid = filename @@ -513,7 +515,7 @@ def emit_wrapped(f, setInterval(check_reload, 500); -""" % constants.root_url) +""" % kiosk_constants.root_url) f.write(f'
') f.write( """ @@ -573,7 +575,7 @@ def renderer_update_internal_stats_page( logger.info( 'renderer: Updating internal render statistics page.' ) - with file_writer.file_writer(constants.render_stats_pagename) as f: + with file_writer.file_writer(kiosk_constants.render_stats_pagename) as f: f.write( '''