3 import gkeepapi # type: ignore
6 from typing import List, Dict
14 class gkeep_renderer(renderer.debuggable_abstaining_renderer):
15 def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None:
16 super(gkeep_renderer, self).__init__(name_to_timeout_dict, True)
17 self.colors_by_name = {
20 "darkblue": "#1F3A5F",
31 self.keep = gkeepapi.Keep()
32 success = self.keep.login(
33 secrets.google_keep_username, secrets.google_keep_password
36 self.debug_print("Connected with gkeep.")
38 self.debug_print("Error connecting with gkeep.")
40 def debug_prefix(self) -> str:
43 def periodic_render(self, key: str) -> bool:
44 strikethrough = re.compile("(\u2611[^\n]*)\n", re.UNICODE)
45 linkify = re.compile(r".*(https?:\/\/\S+).*")
48 result_list = self.keep.find(labels=[self.keep.findLabel("kiosk")])
49 for note in result_list:
51 title = title.replace(" ", "-")
52 title = title.replace("/", "")
54 filename = f"{title}_2_3600.html"
55 contents = note.text + "\n"
56 self.debug_print(f"Note title '{title}'")
57 if contents != "" and not contents.isspace():
58 contents = strikethrough.sub("", contents)
59 self.debug_print(f"Note contents:\n{contents}")
60 contents = contents.replace(
61 "\u2610 ", '<LI><INPUT TYPE="checkbox"> '
63 contents = linkify.sub(r'<a href="\1">\1</a>', contents)
65 individual_lines = contents.split("\n")
66 num_lines = len(individual_lines)
69 for x in individual_lines:
71 if length > max_length:
73 leading_spaces = len(x) - len(x.lstrip(" "))
75 leading_spaces = int(leading_spaces)
77 # self.debug_print(" * (%d) '%s'" % (leading_spaces, x))
78 for y in range(0, leading_spaces):
80 for y in range(0, leading_spaces):
82 contents = contents + x + "\n"
84 individual_lines = contents.split("\n")
85 color = note.color.name.lower()
86 if color in list(self.colors_by_name.keys()):
87 color = self.colors_by_name[color]
89 self.debug_print(f"Unknown color '{color}'")
90 print(f"TITLE: {color} {note.title}")
91 with file_writer.file_writer(filename) as f:
93 <STYLE type="text/css">
94 a:link { color:#88bfbf; }
95 ul { list-style-type:none; }
97 <DIV STYLE="border-radius:25px; border-style:solid; padding:20px; background-color:%s; color:#eeeeee; font-size:x-large;">
101 <p style="color:#ffffff; font-size:larger"><B>{note.title}</B></p>
102 <HR style="border-top:3px solid white;">
105 if num_lines >= 12 and max_length < 120:
107 f"{num_lines} lines (max={max_length} chars): two columns"
109 f.write('<TABLE BORDER=0 WIDTH=100%><TR valign="top">')
111 '<TD WIDTH=50% style="color:#eeeeee; font-size:large">\n'
113 f.write("<FONT><UL STYLE='list-style-type:none'>")
115 for x in individual_lines:
118 if count == num_lines / 2:
119 f.write("</UL></FONT></TD>\n")
121 '<TD WIDTH=50% style="color:#eeeeee; font-size:large">\n'
123 f.write("<FONT><UL STYLE='list-style-type:none'>")
124 f.write("</UL></FONT></TD></TR></TABLE></DIV>\n")
127 f"{num_lines} lines (max={max_length} chars): one column"
129 f.write(f"<FONT><UL>{contents}</UL></FONT>")
132 self.debug_print(f"Note is empty, deleting {filename}.")
133 _ = os.path.join(constants.pages_dir, filename)
142 #x = gkeep_renderer({"Test", 1234})
143 #x.periodic_render("Test")