Skip to content

Commit

Permalink
Create request session
Browse files Browse the repository at this point in the history
  • Loading branch information
laurejt committed Nov 15, 2024
1 parent 6309142 commit 3671540
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ppa/archive/management/commands/hathi_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def add_arguments(self, parser):
nargs="+",
help="Optional list of HathiTrust ids (by default, downloads images for all public HathiTrust volumes)",
)
parser.add_argument(
"--collection",
type=str,
help="Filter volumes by provided PPA collection",
)
parser.add_argument(
"--image-width",
type=int,
Expand Down Expand Up @@ -150,7 +155,7 @@ def download_image(self, page_url: str, out_file: Path) -> bool:
Attempts to download and save an image from the specified URL.
Returns a boolean corresponding to whether the download was successful
"""
response = requests.get(page_url)
response = self.session.get(page_url)
success = False
if response.status_code == requests.codes.ok:
with out_file.open(mode="wb") as writer:
Expand Down Expand Up @@ -250,6 +255,9 @@ def handle(self, *args, **kwargs):
f"Downloading images for {n_vols} record{pluralize(digworks)}",
)

# Create requests session
self.session = requests.Session()

# Initialize progress bar
if self.show_progress:
self.progress_bar = tqdm()
Expand Down

0 comments on commit 3671540

Please sign in to comment.