X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=inline;f=reddit_renderer.py;h=d24d36063d0ce16564c0e8d7a22ed3c4d8253fce;hb=b4e9b9aeb912f411105c56efdce80dbb5fe14d76;hp=30c22e0a4c6021dae7b7d64700ca2d8e90643642;hpb=5c39d86ebc075ccb7be98b1dfab8040b72ff9134;p=kiosk.git
diff --git a/reddit_renderer.py b/reddit_renderer.py
index 30c22e0..d24d360 100644
--- a/reddit_renderer.py
+++ b/reddit_renderer.py
@@ -1,19 +1,23 @@
#!/usr/bin/env python3
-import praw # type: ignore
-import random
+import logging
from typing import Callable, Dict, Iterable, List, Set
-import constants
+import praw # type: ignore
+
+from scottutilz import profanity_filter
+
import file_writer
import grab_bag
import page_builder
-import profanity_filter
import renderer
import kiosk_secrets as secrets
-class reddit_renderer(renderer.debuggable_abstaining_renderer):
+logger = logging.getLogger(__name__)
+
+
+class reddit_renderer(renderer.abstaining_renderer):
"""A renderer to pull text content from reddit."""
def __init__(
@@ -25,7 +29,7 @@ class reddit_renderer(renderer.debuggable_abstaining_renderer):
font_size: int = 24,
additional_filters: Iterable[Callable[[str], bool]] = [],
):
- super(reddit_renderer, self).__init__(name_to_timeout_dict, True)
+ super().__init__(name_to_timeout_dict)
self.subreddit_list = subreddit_list
self.praw = praw.Reddit(
client_id=secrets.reddit_client_id,
@@ -41,14 +45,8 @@ class reddit_renderer(renderer.debuggable_abstaining_renderer):
self.filters.extend(additional_filters)
self.deduper: Set[str] = set()
- def debug_prefix(self) -> str:
- x = ""
- for subreddit in self.subreddit_list:
- x += f"{subreddit} "
- return f"reddit({x.strip()})"
-
def periodic_render(self, key: str) -> bool:
- self.debug_print('called for "%s"' % key)
+ logger.debug('called for "%s"' % key)
if key == "Scrape":
return self.scrape_reddit()
elif key == "Shuffle":
@@ -67,23 +65,24 @@ class reddit_renderer(renderer.debuggable_abstaining_renderer):
filtered = filt.__name__
break
if filtered != "":
- print(f'Filter {filtered} struck down "{title}"')
+ logger.info(f'Filter {filtered} struck down "{title}"')
continue
if msg.ups < self.min_votes:
- print(f'"{title}" doesn\'t have enough upvotes to be interesting')
+ logger.debug(
+ f'"{title}" doesn\'t have enough upvotes to be interesting'
+ )
continue
- try:
- self.deduper.add(title)
- content = f"{msg.ups}"
- if (
- msg.thumbnail != "self"
- and msg.thumbnail != "default"
- and msg.thumbnail != ""
- ):
- content = f''
- self.messages.add(
- f"""
+ self.deduper.add(title)
+ content = f"{msg.ups}"
+ if (
+ msg.thumbnail != "self"
+ and msg.thumbnail != "default"
+ and msg.thumbnail != ""
+ ):
+ content = f'
'
+ self.messages.add(
+ f"""