1 # -*- coding: utf-8 -*-
11 class gkeep_renderer(renderer.debuggable_abstaining_renderer):
12 def __init__(self, name_to_timeout_dict):
13 super(gkeep_renderer, self).__init__(name_to_timeout_dict, True)
14 self.keep = gkeepapi.Keep()
15 success = self.keep.login(secrets.google_keep_username,
16 secrets.google_keep_password)
18 self.debug_print("Connected with gkeep.")
20 self.debug_print("Error connecting with gkeep.")
21 self.colors_by_name = {
24 'darkblue' : '#1F3A5F',
36 def debug_prefix(self):
39 def periodic_render(self, key):
40 strikethrough = re.compile('(\u2611[^\n]*)\n', re.UNICODE)
41 linkify = re.compile(r'.*(https?:\/\/\S+).*')
44 result_list = self.keep.find(labels=[self.keep.findLabel('kiosk')])
45 for note in result_list:
47 title = title.replace(" ", "-")
48 title = title.replace("/", "")
50 filename = "%s_2_3600.html" % title
51 contents = note.text + "\n"
52 self.debug_print("Note title '%s'" % title)
53 if contents != '' and not contents.isspace():
54 contents = strikethrough.sub('', contents)
55 contents = contents.replace(u'\u2610',
56 u'<LI><INPUT TYPE="checkbox"> ')
58 #self.debug_print("Note contents:\n%s" % contents)
59 contents = linkify.sub(r'<a href="\1">\1</a>', contents)
61 individual_lines = contents.split("\n")
62 num_lines = len(individual_lines)
66 for x in individual_lines:
68 if length > max_length:
70 spaces = len(x) - len(x.lstrip(' '))
78 contents = contents + x + "\n"
80 individual_lines = contents.split("\n")
81 color = note.color.name.lower()
82 if color in list(self.colors_by_name.keys()):
83 color = self.colors_by_name[color]
85 self.debug_print("Unknown color '%s'" % color)
86 f = file_writer.file_writer(filename)
88 <STYLE type="text/css">
89 a:link { color:#88bfbf; }
90 ul { list-style-type:none; }
92 <DIV STYLE="border-radius: 25px; border-style: solid; padding: 20px; background-color: %s; color: #eeeeee; font-size: x-large;">
93 <p style="color: #ffffff; font-size:larger"><B>%s</B></p>
94 <HR style="border-top: 3px solid white;">""" % (color, note.title))
95 if num_lines >= 12 and max_length < 120:
96 self.debug_print("%d lines (max=%d chars): two columns" %
97 (num_lines, max_length))
98 f.write("<TABLE BORDER=0 WIDTH=100%%><TR valign=\"top\">")
99 f.write("<TD WIDTH=50%% style=\"color:#eeeeee; font-size:large\">\n")
100 f.write("<FONT><UL>")
102 for x in individual_lines:
105 if count == num_lines / 2:
106 f.write("</UL></FONT></TD>\n")
107 f.write("<TD WIDTH=50%% style=\"color:#eeeeee; font-size:large\">\n")
108 f.write("<FONT><UL>")
109 f.write("</UL></FONT></TD></TR></TABLE></DIV>\n");
111 self.debug_print("%d lines (max=%d chars): one column" %
112 (num_lines, max_length))
113 f.write("<FONT><UL>%s</UL></FONT>" % contents)
117 self.debug_print("Note is empty, deleting %s." % filename)
118 _ = os.path.join(constants.pages_dir, filename)
126 #x = gkeep_renderer({"Test", 1234})
127 #x.periodic_render("Test")