Skip to content

Commit

Permalink
fix: handle case where script hangs if book ID does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Addono committed Aug 21, 2024
1 parent 95b2ada commit 065c75a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hathitrustdownloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ def main():
try:
response = requests.get(url, stream=True)

if response.ok:
if response.status_code == 404:
print(f"Error: Page {page_number} for book with ID '{args.id}' not found.")
return
elif response.status_code == 500:
print(f"Error: The server failed to serve page {page_number} for book '{args.id}', this could indicate that the book identifier is invalid.")
return
elif response.ok:
with open(filename, "wb") as handle:
for data in response.iter_content():
handle.write(data)
Expand All @@ -44,7 +50,7 @@ def main():
except KeyboardInterrupt:
return
except Exception as e:
print(f"An error occurred: {e}. Retrying in 1 second.")
print(f"An error occurred: {e}. Retrying in 1 second. Press Ctrl+C to abort.")
time.sleep(1)

if __name__ == "__main__":
Expand Down

0 comments on commit 065c75a

Please sign in to comment.