Added CSV output.
This commit is contained in:
11
Changelog.md
Normal file
11
Changelog.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## Version 25.07.10
|
||||||
|
|
||||||
|
* Added CSV export
|
||||||
|
* Removed spaces in the output of image dimensions for greater CSV compatibility
|
||||||
|
|
||||||
|
## Version 25.07.08
|
||||||
|
|
||||||
|
Initial release. Minimum viable product
|
||||||
|
|
@ -1,20 +1,24 @@
|
|||||||
import requests
|
import requests
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
import csv
|
||||||
|
|
||||||
# The base URL for ChiliFresh - the UPC, ISSN, and sizes aren't too relevant here
|
# 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"
|
BASE_URL = "https://content.chilifresh.com/?isbn={isbn}&upc=&issn=&size=S"
|
||||||
|
|
||||||
# File management
|
# File management
|
||||||
isbn_file = "isbns.txt" # Provide a single column list of ISBNs in a plain text file
|
isbn_file = "isbns.txt" # Provide a single column list of ISBNs in a plain text file
|
||||||
output_file = "isbn-image-checks.txt" # Your results will drop here
|
output_csv = "isbn-image-checks.csv" # Your results will drop here
|
||||||
|
|
||||||
# Read the ISBNs from the input file
|
# Read the ISBNs from input file
|
||||||
with open(isbn_file, "r") as f:
|
with open(isbn_file, "r") as f:
|
||||||
isbns = [line.strip() for line in f if line.strip()]
|
isbns = [line.strip() for line in f if line.strip()]
|
||||||
|
|
||||||
# Open and prepare the output file
|
# Open and prepare the output file
|
||||||
with open(output_file, "w") as out:
|
with open(output_csv, "w", newline="") as csvfile:
|
||||||
|
writer = csv.writer(csvfile)
|
||||||
|
writer.writerow(["ISBN", "ImageSize"]) # Your CSV headers
|
||||||
|
|
||||||
for isbn in isbns:
|
for isbn in isbns:
|
||||||
url = BASE_URL.format(isbn=isbn)
|
url = BASE_URL.format(isbn=isbn)
|
||||||
try:
|
try:
|
||||||
@ -23,14 +27,16 @@ with open(output_file, "w") as out:
|
|||||||
|
|
||||||
image = Image.open(BytesIO(response.content))
|
image = Image.open(BytesIO(response.content))
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
|
image_size = f"{width}x{height}"
|
||||||
|
|
||||||
out.write(f"{isbn}: {width} x {height} pixels\n")
|
writer.writerow([isbn, image_size])
|
||||||
print(f"Processed ISBN {isbn}: {width} x {height}")
|
print(f"{isbn}: {image_size}")
|
||||||
|
|
||||||
|
# Error handling
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
out.write(f"{isbn}: Image retrieval error - {e}\n")
|
writer.writerow([isbn, f"Image retrieval error - {e}"])
|
||||||
print(f"Error retrieving image for ISBN {isbn}: {e}")
|
print(f"Error retrieving image for {isbn}: {e}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out.write(f"{isbn}: Image processing error - {e}\n")
|
writer.writerow([isbn, f"Image processing error - {e}"])
|
||||||
print(f"Error processing image for ISBN {isbn}: {e}")
|
print(f"Error processing image for {isbn}: {e}")
|
||||||
|
5
isbn-image-checks.csv
Normal file
5
isbn-image-checks.csv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ISBN,ImageSize
|
||||||
|
9780593441299,66x100
|
||||||
|
9780061120084,67x100
|
||||||
|
9780358362159,1x1
|
||||||
|
9781982137274,66x100
|
|
@ -1,4 +0,0 @@
|
|||||||
9780593441299: 66 x 100 pixels
|
|
||||||
9780061120084: 67 x 100 pixels
|
|
||||||
9780358362159: 1 x 1 pixels
|
|
||||||
9781982137274: 66 x 100 pixels
|
|
Reference in New Issue
Block a user