From 84c0b40edf963d8df0bdf7300704cc9ed68b111c Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Thu, 11 Jun 2026 20:41:51 -0400 Subject: [PATCH] bugfix: corrected variable name causing errors, renamed some others --- discorss.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/discorss.py b/discorss.py index 8513a97..ea88c75 100755 --- a/discorss.py +++ b/discorss.py @@ -58,6 +58,7 @@ class Discorss: self.img_src_filter = re.compile(r']+src=["\']([^"\']+)["\']', re.I) self.success_codes = [200, 201, 202, 203, 204, 205, 206] self.app_config = {} + print(f"Logging to {self.log_file_path}") async def _fetch_feed(self, hook): response = await asyncio.to_thread( @@ -98,20 +99,20 @@ class Discorss: async def _process_feed(self, hook, last_check): self.logger.debug("Parsing feed %s...", hook["name"]) - feeds = await self._fetch_feed(hook) + feed = await self._fetch_feed(hook) latest_post = None prev_best = 0 bad_time = False self.logger.debug("About to sort through entries for feed %s ...", hook["name"]) - for feed in feeds["entries"]: + for post in feed["entries"]: try: - published_time = time.mktime(feed["published_parsed"]) + published_time = time.mktime(post["published_parsed"]) published_time = published_time + hook["offset"] except KeyError: - published_time = time.mktime(feed["updated_parsed"]) + published_time = time.mktime(post["updated_parsed"]) bad_time = True if published_time > prev_best: - latest_post = feed + latest_post = post prev_best = published_time if latest_post is None: @@ -251,9 +252,9 @@ class Discorss: # This function gets and formats the brief excerpt that goes in the embed # Different feeds put summaries in different fields, so we pick the best # one and limit it to 250 characters. - def get_description(self, feed, length=250, min_length=150, addons=None): + def get_description(self, post, length=250, min_length=150, addons=None): try: - temporary_string = str(feed["summary_detail"]["value"]) + temporary_string = str(post["summary_detail"]["value"]) temporary_string = self.html_filter.sub("", temporary_string) while length > min_length: if temporary_string[length - 1 : length] == " ": @@ -261,7 +262,7 @@ class Discorss: else: length -= 1 except KeyError: - temporary_string = str(feed["description"]) + temporary_string = str(post["description"]) temporary_string = self.html_filter.sub("", temporary_string) while length > min_length: if temporary_string[length - 1 : length] == " ": @@ -276,28 +277,28 @@ class Discorss: # attempting to extract image previews from feeds which primarily feature # images, like NASA's Picture of the Day feed - def get_image_url(self, feed): + def get_image_url(self, post): image_candidates = [] # check the most common fields, this should catch the majority of image # feeds' embedded urls - for media in feed.get("media_content", []): + for media in post.get("media_content", []): if self.is_image_url(media.get("url"), media.get("type")): image_candidates.append(media["url"]) - for enclosure in feed.get("enclosures", []): + for enclosure in post.get("enclosures", []): if self.is_image_url(enclosure.get("href"), enclosure.get("type")): image_candidates.append(enclosure["href"]) - for link in feed.get("links", []): + for link in post.get("links", []): if self.is_image_url(link.get("href"), link.get("type")): image_candidates.append(link["href"]) - for media in feed.get("media_thumbnail", []): + for media in post.get("media_thumbnail", []): if self.is_image_url(media.get("url"), media.get("type")): image_candidates.append(media["url"]) for field in ["summary_detail", "content"]: - value = feed.get(field) + value = post.get(field) if isinstance(value, list): values = [item.get("value", "") for item in value] elif isinstance(value, dict): @@ -308,7 +309,7 @@ class Discorss: match = self.img_src_filter.search(str(text)) if match and self.is_image_url(match.group(1)): image_candidates.append(match.group(1)) - self.logger.debug("Found the following image candidates in %s...", feed["name"]) + self.logger.debug("Found the following image candidates in %s...", post["title"]) for i in image_candidates: self.logger.debug("%s", i) if len(image_candidates) > 0: @@ -336,7 +337,7 @@ class Discorss: logging.basicConfig( filename=self.log_file_path, encoding="utf-8", - level=logging.ERROR, + level=logging.INFO, datefmt="%m/%d/%Y %H:%M:%S", format="%(asctime)s [%(threadName)s] -> %(levelname)s: %(message)s", )