5 from typing import Dict, Optional, List, Tuple
7 from pyutils.files import file_utils
9 import kiosk_constants as constants
16 logger = logging.getLogger(__name__)
18 RECIPE_PAGE = "recipe-unwrapped_1_82400.html"
19 RECIPE_PATH = os.path.join(constants.pages_dir, RECIPE_PAGE)
22 class RecipeTrigger(trigger.trigger):
23 def get_triggered_page_list(self) -> Optional[List[Tuple[str, int]]]:
24 if globals.get("recipe_page_triggered"):
25 logger.debug("Recipe page is triggered!")
26 return [(RECIPE_PAGE, trigger.trigger.PRIORITY_HIGH)]
30 class RecipeRenderer(renderer.abstaining_renderer):
34 name_to_timeout_dict: Dict[str, int],
36 super().__init__(name_to_timeout_dict)
37 self.url_location = url_location
39 def periodic_render(self, key: str) -> bool:
41 if file_utils.does_path_exist(self.url_location):
42 with open(self.url_location, "r") as rf:
45 logger.debug(f"Read {url} from {self.url_location}, writing the page")
47 if url and len(url) > 0:
48 with file_writer.file_writer(RECIPE_PATH) as f:
54 <title>Current Recipe</title>
67 const sleep = (milliseconds) => {
68 return new Promise(resolve => setTimeout(resolve, milliseconds))
71 function iframeRef( frameRef ) {
72 return frameRef.contentWindow
73 ? frameRef.contentWindow.document
74 : frameRef.contentDocument
77 function countdown() {
81 var deltaMs = now.getTime() - loadedDate.getTime();
83 var remainingMs = (totalMs - deltaMs);
85 if (remainingMs <= 0) {
86 // Reload unconditionally every two minutes.
87 window.location.reload(true);
90 // Get rid of the recipe title bar, it's too big.
91 var recipe = iframeRef(document.getElementById('embedded'))
92 recipe.getElementById('id_main_nav').style.visibility = 'hidden';
94 // Brief sleep before doing it all over again.
95 sleep(1000).then(() => {
106 <body onload='javascript:loadedDate = new Date(); countdown();'>
109 <IFRAME ID='embedded' WIDTH=100% HEIGHT=100% SRC="{url}"></IFRAME>
119 logger.debug("We are no longer triggered.")
120 if file_utils.does_path_exist(RECIPE_PATH):
121 file_utils.remove(RECIPE_PATH)
123 logger.debug("We are triggered.")
124 globals.put("recipe_page_triggered", triggered)