Well, actually, no luck on the import, but the script here works:
- takes a Calibre catalog as input
- the covers must be in the first column
- outputs a css file with the covers as base64 BLOB
Code:
import csv
import base64
#assume cover paths are in the first column of the csv
with open('C:\Users\Fra\Documents\_permanent\Papier20150901.csv', 'rb') as file1, open('C:\Users\Fra\Documents\_permanent\Papier20150901covers.csv', 'wb') as file2:
reader = csv.reader(file1, delimiter=',' , quotechar='"', doublequote = True)
#No quotes around the headers
#write without looking for path
headers = next(reader, None) # returns the headers or `None` if the input is empty
if headers:
writer = csv.writer(file2, delimiter=',', quoting=csv.QUOTE_NONE)
writer.writerow(headers)
#For all other lines, put double quotes around each cell
writer = csv.writer(file2, delimiter=',', quoting=csv.QUOTE_ALL)
for i, row in enumerate(reader):
if row[0] == "":
writer.writerow(row)
else:
with open(row[0], "rb") as image_file:
row[0] = base64.b64encode(image_file.read())
writer.writerow(row)
Hope it helps someone...
François