X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gkeep_renderer.py;h=4a3725b29d5867808297bb4557e34079114b80c6;hb=0bee476055b15d8de59c74b61e5c56f214b83941;hp=cba8596777aeb5689ed15e4b5f9a2e21aabf7d53;hpb=5e241dc47e497c547463cecc07946ea6882835a7;p=kiosk.git diff --git a/gkeep_renderer.py b/gkeep_renderer.py index cba8596..4a3725b 100644 --- a/gkeep_renderer.py +++ b/gkeep_renderer.py @@ -1,25 +1,19 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 -import constants -import file_writer -import gkeepapi +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): + def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None: 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.") self.colors_by_name = { "white": "#002222", "green": "#345920", @@ -34,11 +28,19 @@ 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 + ) + if success: + self.debug_print("Connected with gkeep.") + else: + self.debug_print("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+).*") @@ -49,14 +51,14 @@ 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) + self.debug_print(f"Note title '{title}'") if contents != "" and not contents.isspace(): contents = strikethrough.sub("", contents) - self.debug_print("Note contents:\n%s" % contents) + self.debug_print(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("
|