diff --git a/discorss.py b/discorss.py index be0ce2c..8513a97 100755 --- a/discorss.py +++ b/discorss.py @@ -58,7 +58,6 @@ 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( @@ -99,20 +98,20 @@ class Discorss: async def _process_feed(self, hook, last_check): self.logger.debug("Parsing feed %s...", hook["name"]) - feed = await self._fetch_feed(hook) + feeds = 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 post in feed["entries"]: + for feed in feeds["entries"]: try: - published_time = time.mktime(post["published_parsed"]) + published_time = time.mktime(feed["published_parsed"]) published_time = published_time + hook["offset"] except KeyError: - published_time = time.mktime(post["updated_parsed"]) + published_time = time.mktime(feed["updated_parsed"]) bad_time = True if published_time > prev_best: - latest_post = post + latest_post = feed prev_best = published_time if latest_post is None: @@ -252,9 +251,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, post, length=250, min_length=150, addons=None): + def get_description(self, feed, length=250, min_length=150, addons=None): try: - temporary_string = str(post["summary_detail"]["value"]) + temporary_string = str(feed["summary_detail"]["value"]) temporary_string = self.html_filter.sub("", temporary_string) while length > min_length: if temporary_string[length - 1 : length] == " ": @@ -262,7 +261,7 @@ class Discorss: else: length -= 1 except KeyError: - temporary_string = str(post["description"]) + temporary_string = str(feed["description"]) temporary_string = self.html_filter.sub("", temporary_string) while length > min_length: if temporary_string[length - 1 : length] == " ": @@ -277,28 +276,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, post): + def get_image_url(self, feed): image_candidates = [] # check the most common fields, this should catch the majority of image # feeds' embedded urls - for media in post.get("media_content", []): + for media in feed.get("media_content", []): if self.is_image_url(media.get("url"), media.get("type")): image_candidates.append(media["url"]) - for enclosure in post.get("enclosures", []): + for enclosure in feed.get("enclosures", []): if self.is_image_url(enclosure.get("href"), enclosure.get("type")): image_candidates.append(enclosure["href"]) - for link in post.get("links", []): + for link in feed.get("links", []): if self.is_image_url(link.get("href"), link.get("type")): image_candidates.append(link["href"]) - for media in post.get("media_thumbnail", []): + for media in feed.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 = post.get(field) + value = feed.get(field) if isinstance(value, list): values = [item.get("value", "") for item in value] elif isinstance(value, dict): @@ -309,7 +308,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...", post["title"]) + self.logger.debug("Found the following image candidates in %s...", feed["name"]) for i in image_candidates: self.logger.debug("%s", i) if len(image_candidates) > 0: @@ -337,7 +336,7 @@ class Discorss: logging.basicConfig( filename=self.log_file_path, encoding="utf-8", - level=logging.DEBUG, + level=logging.ERROR, datefmt="%m/%d/%Y %H:%M:%S", format="%(asctime)s [%(threadName)s] -> %(levelname)s: %(message)s", ) @@ -392,8 +391,6 @@ class Discorss: self.app_config["lastupdate"] = self.now with open(self.config_file_path, "w") as config_file: json.dump(self.app_config, config_file, indent=4) - - self.logger.info("Stopping DiscoRSS version {}...".format(self.APP_VERSION)) return