#!/usr/bin/env python3 import gkeepapi # type: ignore import os import re from typing import List, Dict import constants import file_writer import renderer import secrets class gkeep_renderer(renderer.debuggable_abstaining_renderer): def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None: super(gkeep_renderer, self).__init__(name_to_timeout_dict, True) self.colors_by_name = { "white": "#002222", "green": "#345920", "darkblue": "#1F3A5F", "blue": "#2D545E", "orange": "#604A19", "red": "#5C2B29", "purple": "#42275E", "pink": "#5B2245", "yellow": "#635D19", "brown": "#442F19", "gray": "#3c3f4c", "teal": "#16504B", } self.keep = gkeepapi.Keep() success = self.keep.login( secrets.google_keep_username, secrets.google_keep_password ) if success: self.debug_print("Connected with gkeep.") else: self.debug_print("Error connecting with gkeep.") def debug_prefix(self) -> str: return "gkeep" def periodic_render(self, key: str) -> bool: strikethrough = re.compile("(\u2611[^\n]*)\n", re.UNICODE) linkify = re.compile(r".*(https?:\/\/\S+).*") self.keep.sync() result_list = self.keep.find(labels=[self.keep.findLabel("kiosk")]) for note in result_list: title = note.title title = title.replace(" ", "-") title = title.replace("/", "") filename = f"{title}_2_3600.html" contents = note.text + "\n" self.debug_print(f"Note title '{title}'") if contents != "" and not contents.isspace(): contents = strikethrough.sub("", contents) self.debug_print(f"Note contents:\n{contents}") contents = contents.replace( "\u2610 ", '
{note.title}
\n'
)
f.write("
| \n")
f.write(
'\n'
)
f.write("
|