Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lenient epub generation #109

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading