Skip to content

Commit

Permalink
Lenient epub generation (#109)
Browse files Browse the repository at this point in the history
* allow failures when fetching images on epub export

* add logging
  • Loading branch information
facundoolano authored Aug 18, 2024
1 parent 75c1992 commit 909b0bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions feedi/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

USER_AGENT = "feedi/0.1.0 (+https://github.com/facundoolano/feedi)"
TIMEOUT_SECONDS = 5
TIMEOUT_SLOWER = 10

requests = requests.Session()
requests.headers.update({"User-Agent": USER_AGENT})
Expand Down
11 changes: 8 additions & 3 deletions feedi/scraping.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from bs4 import BeautifulSoup
from PIL import Image

from feedi.requests import USER_AGENT, requests
from feedi.requests import USER_AGENT, requests, TIMEOUT_SLOWER
from requests.exceptions import RequestException

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -149,8 +150,12 @@ def package_epub(url, article):
img["src"] = img_filename

# download the image and save into the files subdir of the zip
response = requests.get(img_url)
if not response.ok:
try:
response = requests.get(img_url, timeout=TIMEOUT_SLOWER)
if not response.ok:
continue
except RequestException:
logger.exception("error fetching image during epub generation: %s", img_url)
continue

with zip.open(img_filename, "w") as dest_file:
Expand Down

0 comments on commit 909b0bb

Please sign in to comment.