downloads cedarville publishing books as pdf
1#!/usr/bin/env python3
2"""
3Download all page layers (SVG + high-res WebP) from Cedarville textbook.
4"""
5
6import requests
7from pathlib import Path
8import time
9import sys
10
11GUID = "abc80436024deb05cedb27129b7ae6b0"
12BASE_URL = "https://publications.cedarville.edu/cedrus_press/invitation_to_cybersecurity/files/assets"
13
14def download_svg(page_num, output_dir):
15 """Download SVG text layer."""
16 url = f"{BASE_URL}/common/page-vectorlayers/{page_num:04d}.svg?uni={GUID}"
17 output_file = output_dir / f"page_{page_num:04d}.svg"
18
19 try:
20 response = requests.get(url, timeout=30)
21 if response.status_code == 200:
22 with open(output_file, 'wb') as f:
23 f.write(response.content)
24 return True
25 except:
26 pass
27 return False
28
29def download_webp(page_num, output_dir):
30 """Download high-res WebP background."""
31 url = f"{BASE_URL}/common/page-html5-substrates/page{page_num:04d}_3.webp?uni={GUID}"
32 output_file = output_dir / f"page_{page_num:04d}_3.webp"
33
34 try:
35 response = requests.get(url, timeout=30)
36 if response.status_code == 200:
37 with open(output_file, 'wb') as f:
38 f.write(response.content)
39 return True
40 except:
41 pass
42 return False
43
44def main():
45 script_dir = Path(__file__).parent
46 svg_dir = script_dir / "svg_layers"
47 webp_dir = script_dir / "webp_highres"
48
49 svg_dir.mkdir(exist_ok=True)
50 webp_dir.mkdir(exist_ok=True)
51
52 print("Downloading 340 pages (SVG + high-res WebP)...")
53 print(f" SVG layers → {svg_dir}")
54 print(f" WebP layers → {webp_dir}")
55 print()
56
57 svg_count = 0
58 webp_count = 0
59
60 for page_num in range(1, 341):
61 # Download both layers
62 if download_svg(page_num, svg_dir):
63 svg_count += 1
64 if download_webp(page_num, webp_dir):
65 webp_count += 1
66
67 # Progress update
68 if page_num % 20 == 0:
69 print(f" Progress: {page_num}/340 (SVG: {svg_count}, WebP: {webp_count})")
70 sys.stdout.flush()
71
72 # Be polite to server
73 time.sleep(0.3)
74
75 print()
76 print(f"Download complete!")
77 print(f" SVG layers: {svg_count}/340")
78 print(f" WebP layers: {webp_count}/340")
79
80if __name__ == "__main__":
81 main()