43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import requests
|
|
from PIL import Image
|
|
from io import BytesIO
|
|
import csv
|
|
|
|
# The base URL for ChiliFresh - the UPC, ISSN, and sizes aren't too relevant here
|
|
BASE_URL = "https://content.chilifresh.com/?isbn={isbn}&upc=&issn=&size=S"
|
|
|
|
# File management
|
|
isbn_file = "isbns.txt" # Provide a single column list of ISBNs in a plain text file
|
|
output_csv = "isbn-image-checks.csv" # Your results will drop here
|
|
|
|
# Read the ISBNs from input file
|
|
with open(isbn_file, "r") as f:
|
|
isbns = [line.strip() for line in f if line.strip()]
|
|
|
|
# Open and prepare the output file
|
|
with open(output_csv, "w", newline="") as csvfile:
|
|
writer = csv.writer(csvfile)
|
|
writer.writerow(["ISBN", "ImageSize"]) # Your CSV headers
|
|
|
|
for isbn in isbns:
|
|
url = BASE_URL.format(isbn=isbn)
|
|
try:
|
|
response = requests.get(url)
|
|
response.raise_for_status()
|
|
|
|
image = Image.open(BytesIO(response.content))
|
|
width, height = image.size
|
|
image_size = f"{width}x{height}"
|
|
|
|
writer.writerow([isbn, image_size])
|
|
print(f"{isbn}: {image_size}")
|
|
|
|
# Error handling
|
|
except requests.exceptions.RequestException as e:
|
|
writer.writerow([isbn, f"Image retrieval error - {e}"])
|
|
print(f"Error retrieving image for {isbn}: {e}")
|
|
|
|
except Exception as e:
|
|
writer.writerow([isbn, f"Image processing error - {e}"])
|
|
print(f"Error processing image for {isbn}: {e}")
|