Make it so that I can verbally scroll chrome.
[kiosk.git] / kiosk.py
index b1bdb1c7c7e9b6f8319b46288c5995fac95c95f2..a7350ec41b2ee3d1d2c779f764436ef146e270ec 100755 (executable)
--- a/kiosk.py
+++ b/kiosk.py
@@ -19,12 +19,14 @@ import numpy as np
 import pvporcupine
 import pytz
 
-import bootstrap
-import config
-import datetime_utils
-import file_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
@@ -131,6 +133,16 @@ def process_command(command: str, page_history: List[str], page_chooser) -> str:
     page = None
     if 'hold' in command:
         page = page_history[0]
+    elif 'down' in command:
+        os.system(
+            "xdotool search --onlyvisible \"chrom\" windowactivate click --repeat 8 5"
+        )
+        return None
+    elif 'up' in command:
+        os.system(
+            "xdotool search --onlyvisible \"chrom\" windowactivate click --repeat 8 4"
+        )
+        return None
     elif 'back' in command:
         page = page_history[1]
     elif 'skip' in command:
@@ -142,9 +154,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 +234,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:
@@ -238,8 +250,10 @@ def thread_change_current(command_queue: Queue) -> None:
 
         if command is not None:
             logger.info(f'chooser: We got a verbal command ("{command}"), parsing it...')
-            triggered = True
             page = process_command(command, page_history, page_chooser)
+
+        if page:
+            triggered = True
         else:
             while True:
                 (page, triggered) = page_chooser.choose_next_page()
@@ -255,7 +269,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 +277,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 +302,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)
@@ -346,9 +360,9 @@ 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 = file_utils.describe_file_ctime(f"pages/{filename}")
     bgcolor = pick_background_color()
@@ -513,7 +527,7 @@ def emit_wrapped(f,
   setInterval(check_reload, 500);
   </SCRIPT>
 </HEAD>
-""" % constants.root_url)
+""" % kiosk_constants.root_url)
     f.write(f'<BODY BGCOLOR="#{bgcolor}">')
     f.write(
 """
@@ -573,7 +587,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(
 '''
 <CENTER>
@@ -669,7 +683,7 @@ f'''
         # Update a page about internal stats of renderers.
         renderer_update_internal_stats_page(last_render, render_counts, render_times)
         logger.info('renderer: having a little nap...')
-        time.sleep(constants.render_period_sec)
+        time.sleep(kiosk_constants.render_period_sec)
 
 
 @bootstrap.initialize
@@ -729,7 +743,7 @@ def main() -> None:
 
         # Have a little break and then check to make sure all threads are still alive.
         logger.debug('watchdog: having a little nap.')
-        time.sleep(constants.check_threads_period_sec)
+        time.sleep(kiosk_constants.check_threads_period_sec)
 
 
 if __name__ == "__main__":