#####
# Download Atari manual pages from Web Internet Archive
# by GLaDOS 2024
#####
import requests
import os
from time import sleep
base_url: str = "https://web.archive.org/web/20170102173712if_/http://atari8.cz/calp/data/hod_tm2/img/pg_"
output_folder = "images"
def download_image(url, filename, max_retries=5):
for attempt in range(max_retries):
try:
response = requests.get(url, timeout=120)
if response.status_code == 200:
with open(filename, 'wb') as f:
f.write(response.content)
print(f"Image downloaded successfully: {filename}")
return True
else:
print(f"Failed to download image. Status code: {response.status_code}")
except Exception as e:
print(f"Error downloading image: {e}")
print(f"Retry {attempt + 1}/{max_retries}...")
sleep(5) # Wait for 5 seconds before retrying
print(f"Failed to download image after {max_retries} attempts: {url}")
return False
def download_images(start_index, end_index):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for i in range(start_index, end_index + 1):
url = f"{base_url}{str(i).zfill(3)}{'a' if i == 0 else ''}.gif"
filename = os.path.join(output_folder, f"image_{str(i).zfill(3)}.gif")
print(f"Downloading image {i}...")
if not download_image(url, filename):
if i == 0:
continue # Skip to the next image if page 0 failed
else:
print("Stopping program due to consecutive failures.")
break
if __name__ == "__main__":
download_images(0, 73) # Change the range according to your needs