#!/usr/bin/env python3 import logging import os from typing import Dict, Optional, List, Tuple from pyutils.files import file_utils import kiosk_constants as constants import file_writer import globals import renderer import trigger logger = logging.getLogger(__name__) RECIPE_PAGE = "recipe-unwrapped_1_82400.html" RECIPE_PATH = os.path.join(constants.pages_dir, RECIPE_PAGE) class RecipeTrigger(trigger.trigger): def get_triggered_page_list(self) -> Optional[List[Tuple[str, int]]]: if globals.get("recipe_page_triggered"): logger.debug("Recipe page is triggered!") return [(RECIPE_PAGE, trigger.trigger.PRIORITY_HIGH)] return None class RecipeRenderer(renderer.abstaining_renderer): def __init__( self, url_location: str, name_to_timeout_dict: Dict[str, int], ) -> None: super().__init__(name_to_timeout_dict) self.url_location = url_location def periodic_render(self, key: str) -> bool: triggered = False if file_utils.does_path_exist(self.url_location): with open(self.url_location, "r") as rf: url = rf.read() url.strip() logger.debug(f"Read {url} from {self.url_location}, writing the page") if url and len(url) > 0: with file_writer.file_writer(RECIPE_PATH) as f: f.write( """