View Single Post
Old 09-02-2015, 10:18 PM   #16
fxp33
Addict
fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.fxp33 figured out that Keyser Söze was the Kevin Spacey character in less than 20 minutes.
 
Posts: 262
Karma: 110864
Join Date: Mar 2013
Location: Bordeaux, France
Device: Kobo Glo, Aura HD, kindle paperwhite
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
fxp33 is offline   Reply With Quote