1 # -*- coding: utf-8 -*-
12 class gkeep_renderer(renderer.debuggable_abstaining_renderer):
13 def __init__(self, name_to_timeout_dict):
14 super(gkeep_renderer, self).__init__(name_to_timeout_dict, True)
15 self.keep = gkeepapi.Keep()
16 success = self.keep.login(
17 secrets.google_keep_username, secrets.google_keep_password
20 self.debug_print("Connected with gkeep.")
22 self.debug_print("Error connecting with gkeep.")
23 self.colors_by_name = {
26 "darkblue": "#1F3A5F",
38 def debug_prefix(self):
41 def periodic_render(self, key):
42 strikethrough = re.compile("(\u2611[^\n]*)\n", re.UNICODE)
43 linkify = re.compile(r".*(https?:\/\/\S+).*")
46 result_list = self.keep.find(labels=[self.keep.findLabel("kiosk")])
47 for note in result_list:
49 title = title.replace(" ", "-")
50 title = title.replace("/", "")
52 filename = "%s_2_3600.html" % title
53 contents = note.text + "\n"
54 self.debug_print("Note title '%s'" % title)
55 if contents != "" and not contents.isspace():
56 contents = strikethrough.sub("", contents)
57 self.debug_print("Note contents:\n%s" % contents)
58 contents = contents.replace(
59 u"\u2610 ", u'<LI><INPUT TYPE="checkbox"> '
61 contents = linkify.sub(r'<a href="\1">\1</a>', contents)
63 individual_lines = contents.split("\n")
64 num_lines = len(individual_lines)
67 for x in individual_lines:
69 if length > max_length:
71 leading_spaces = len(x) - len(x.lstrip(" "))
73 leading_spaces = int(leading_spaces)
75 # self.debug_print(" * (%d) '%s'" % (leading_spaces, x))
76 for y in range(0, leading_spaces):
78 for y in range(0, leading_spaces):
80 contents = contents + x + "\n"
82 individual_lines = contents.split("\n")
83 color = note.color.name.lower()
84 if color in list(self.colors_by_name.keys()):
85 color = self.colors_by_name[color]
87 self.debug_print("Unknown color '%s'" % color)
88 f = file_writer.file_writer(filename)
91 <STYLE type="text/css">
92 a:link { color:#88bfbf; }
93 ul { list-style-type:none; }
95 <DIV STYLE="border-radius: 25px; border-style: solid; padding: 20px; background-color: %s; color: #eeeeee; font-size: x-large;">
96 <p style="color: #ffffff; font-size:larger"><B>%s</B></p>
97 <HR style="border-top: 3px solid white;">"""
100 if num_lines >= 12 and max_length < 120:
102 "%d lines (max=%d chars): two columns" % (num_lines, max_length)
104 f.write('<TABLE BORDER=0 WIDTH=100%%><TR valign="top">')
105 f.write('<TD WIDTH=50%% style="color:#eeeeee; font-size:large">\n')
106 f.write("<FONT><UL STYLE='list-style-type:none'>")
108 for x in individual_lines:
111 if count == num_lines / 2:
112 f.write("</UL></FONT></TD>\n")
114 '<TD WIDTH=50%% style="color:#eeeeee; font-size:large">\n'
116 f.write("<FONT><UL STYLE='list-style-type:none'>")
117 f.write("</UL></FONT></TD></TR></TABLE></DIV>\n")
120 "%d lines (max=%d chars): one column" % (num_lines, max_length)
122 f.write("<FONT><UL>%s</UL></FONT>" % contents)
126 self.debug_print("Note is empty, deleting %s." % filename)
127 _ = os.path.join(constants.pages_dir, filename)
136 # x = gkeep_renderer({"Test", 1234})
137 # x.periodic_render("Test")