From b1cb9f77778d47a01811386d9d2808d789416e99 Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Wed, 10 Jan 2024 21:20:02 +0000 Subject: [PATCH] Handle readability exception --- slixfeed/action.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/slixfeed/action.py b/slixfeed/action.py index 5615681..9ddd4e0 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -24,7 +24,6 @@ from http.client import IncompleteRead from feedparser import parse import logging from lxml import html -from readability import Document import slixfeed.config as config import slixfeed.crawl as crawl from slixfeed.datetime import ( @@ -60,6 +59,13 @@ except: "Package pdfkit was not found.\n" "PDF support is disabled.") +try: + from readability import Document +except: + logging.info( + "Package readability was not found.\n" + "Arc90 Lab algorithm is disabled.") + def log_to_markdown(timestamp, filename, jid, message): """ @@ -706,9 +712,14 @@ async def get_content(url): data = result[0] code = result[1] if data: - document = Document(result[0]) - content = document.summary() - info = [code, content] + try: + document = Document(result[0]) + content = document.summary() + info = [code, content] + except: + logging.warning( + "Install package readability.") + info = result else: info = [code, None] return info