X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gkeep_renderer.py;h=c07ebd6a4c060cfb3f02a64001ed79528296b8e4;hb=8662cd30375579ae858104e8d1a11e1c9b6ce17b;hp=cba8596777aeb5689ed15e4b5f9a2e21aabf7d53;hpb=5e241dc47e497c547463cecc07946ea6882835a7;p=kiosk.git diff --git a/gkeep_renderer.py b/gkeep_renderer.py index cba8596..c07ebd6 100644 --- a/gkeep_renderer.py +++ b/gkeep_renderer.py @@ -1,25 +1,24 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 -import constants -import file_writer -import gkeepapi +import logging import os import re +from typing import Dict + +import gkeepapi # type: ignore + +import kiosk_constants +import file_writer import renderer -import secrets +import kiosk_secrets as secrets -class gkeep_renderer(renderer.debuggable_abstaining_renderer): - def __init__(self, name_to_timeout_dict): - super(gkeep_renderer, self).__init__(name_to_timeout_dict, True) - 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.") +logger = logging.getLogger(__file__) + + +class gkeep_renderer(renderer.abstaining_renderer): + def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None: + super().__init__(name_to_timeout_dict) self.colors_by_name = { "white": "#002222", "green": "#345920", @@ -34,13 +33,23 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer): "gray": "#3c3f4c", "teal": "#16504B", } + self.keep = gkeepapi.Keep() + success = self.keep.login( + secrets.google_keep_username, + secrets.google_keep_password, + secrets.google_keep_mac, + ) + if success: + logger.debug("Connected with gkeep.") + else: + logger.debug("Error connecting with gkeep.") - def debug_prefix(self): + def debug_prefix(self) -> str: return "gkeep" - def periodic_render(self, key): + def periodic_render(self, key: str) -> bool: strikethrough = re.compile("(\u2611[^\n]*)\n", re.UNICODE) - linkify = re.compile(r".*(https?:\/\/\S+).*") + #linkify = re.compile(r".*(https?:\/\/\S+).*") self.keep.sync() result_list = self.keep.find(labels=[self.keep.findLabel("kiosk")]) @@ -49,30 +58,26 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer): title = title.replace(" ", "-") title = title.replace("/", "") - filename = "%s_2_3600.html" % title + filename = f"{title}_2_3600.html" contents = note.text + "\n" - self.debug_print("Note title '%s'" % title) + logger.debug(f"Note title '{title}'") if contents != "" and not contents.isspace(): contents = strikethrough.sub("", contents) - self.debug_print("Note contents:\n%s" % contents) + logger.debug(f"Note contents:\n{contents}") contents = contents.replace( - u"\u2610 ", u'
%s
-\n')
- f.write("
| \n")
- f.write(
- '\n'
+
+""" % color
)
- f.write("
|
{note.title}
+\n'
+ )
+ f.write("
| \n")
+ f.write(
+ '\n'
+ )
+ f.write("
|