#!/usr/bin/env python3
-import gkeepapi # type: ignore
+import logging
import os
import re
-from typing import List, Dict
+from typing import Dict
+
+import gkeepapi # type: ignore
-import constants
+import kiosk_constants
import file_writer
import renderer
-import secrets
+import kiosk_secrets as secrets
+
+
+logger = logging.getLogger(__file__)
-class gkeep_renderer(renderer.debuggable_abstaining_renderer):
+class gkeep_renderer(renderer.abstaining_renderer):
def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None:
- super(gkeep_renderer, self).__init__(name_to_timeout_dict, True)
+ super().__init__(name_to_timeout_dict)
self.colors_by_name = {
"white": "#002222",
"green": "#345920",
secrets.google_keep_username, secrets.google_keep_password
)
if success:
- self.debug_print("Connected with gkeep.")
+ logger.debug("Connected with gkeep.")
else:
- self.debug_print("Error connecting with gkeep.")
+ logger.debug("Error connecting with gkeep.")
def debug_prefix(self) -> str:
return "gkeep"
filename = f"{title}_2_3600.html"
contents = note.text + "\n"
- self.debug_print(f"Note title '{title}'")
+ logger.debug(f"Note title '{title}'")
if contents != "" and not contents.isspace():
contents = strikethrough.sub("", contents)
- self.debug_print(f"Note contents:\n{contents}")
+ logger.debug(f"Note contents:\n{contents}")
contents = contents.replace(
"\u2610 ", '<LI><INPUT TYPE="checkbox"> '
)
- contents = linkify.sub(r'<a href="\1">\1</a>', contents)
+ #contents = linkify.sub(r'<a href="\1">\1</a>', contents)
individual_lines = contents.split("\n")
num_lines = len(individual_lines)
- max_length = 0
contents = ""
for x in individual_lines:
length = len(x)
- if length > max_length:
- max_length = length
leading_spaces = len(x) - len(x.lstrip(" "))
leading_spaces //= 2
leading_spaces = int(leading_spaces)
x = x.lstrip(" ")
- # self.debug_print(" * (%d) '%s'" % (leading_spaces, x))
+ # logger.debug(" * (%d) '%s'" % (leading_spaces, x))
for y in range(0, leading_spaces):
x = "<UL>" + x
for y in range(0, leading_spaces):
if color in list(self.colors_by_name.keys()):
color = self.colors_by_name[color]
else:
- self.debug_print(f"Unknown color '{color}'")
+ logger.debug(f"Unknown color '{color}'")
print(f"TITLE: {color} {note.title}")
with file_writer.file_writer(filename) as f:
f.write("""
<HR style="border-top:3px solid white;">
"""
)
- if num_lines >= 12 and max_length < 120:
- self.debug_print(
- f"{num_lines} lines (max={max_length} chars): two columns"
+ if num_lines >= 12:
+ logger.debug(
+ f"{num_lines} lines: two column mode"
)
f.write('<TABLE BORDER=0 WIDTH=100%><TR valign="top">')
f.write(
f.write("<FONT><UL STYLE='list-style-type:none'>")
f.write("</UL></FONT></TD></TR></TABLE></DIV>\n")
else:
- self.debug_print(
- f"{num_lines} lines (max={max_length} chars): one column"
+ logger.debug(
+ f"{num_lines} lines: one column mode"
)
f.write(f"<FONT><UL>{contents}</UL></FONT>")
f.write("</DIV>")
else:
- self.debug_print(f"Note is empty, deleting {filename}.")
- _ = os.path.join(constants.pages_dir, filename)
+ logger.debug(f"Note is empty, deleting {filename}.")
+ _ = os.path.join(kiosk_constants.pages_dir, filename)
try:
os.remove(_)
except:
# Test
+#logger.setLevel(logging.DEBUG)
+#ch = logging.StreamHandler()
+#ch.setLevel(logging.DEBUG)
+#formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+#ch.setFormatter(formatter)
+#logger.addHandler(ch)
#x = gkeep_renderer({"Test", 1234})
#x.periodic_render("Test")