diff --git a/ppa/archive/management/commands/hathi_images.py b/ppa/archive/management/commands/hathi_images.py index 990dbea0..72bcae21 100644 --- a/ppa/archive/management/commands/hathi_images.py +++ b/ppa/archive/management/commands/hathi_images.py @@ -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, @@ -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: @@ -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()