View Single Post
Old 07-08-2010, 01:22 PM   #1
LARdT
The LARdT of E-Books
LARdT began at the beginning.
 
LARdT's Avatar
 
Posts: 106
Karma: 46
Join Date: Dec 2009
Device: HANLIN V3ext (Papyre 6.1)
Mass import of books metadata from an ASCII file: HELP NEEDED

Kovid,

As far as I'm a complete newbie in python I would be very grateful if you could give me a big hand here.

I would like to program a "complement" in order to be able to import a lot of records with books data into CALIBRE. To make it easier we will suppose that all the book records are new; so we do not have to control anything. We only need to be able to make the mass input into CALIBRE. We will make refinements later. (As soon as I learn a litlle of Python)

We will suppose we have an ASCII file, comma delimited (or whatever), with the metadata of the different books in it and one directory with the JPG files that will make the covers.

Lets suppose we have the following field structure in the ASCII file:

First part of author's name, Second part of author's name, Book Title, Input date, path to JPG cover file

so it will look something like this:

"Jules", "Verne", "20.000 leagues under the sea", "'08/07/2010", "C:\MYCOVERS\20000leaguescover.JPG"

If the program, were some kind of Basic it would look something like this:

Open the ASCII data file for reading

Read the ASCII file, phrase by phrase (line) using some kind of loop

Using the delimiter character ("comma" in our example) you get the phrase chopped in its different fields.
If it were easier we Could use a FIXED LENGHT fields ASCII file and would do the "chopping" using the lenghts of fields.

We make the correspondence between the pieces of our ASCII chopped line and CALIBRE database fields.



Obviously we have been able to OPEN the CALIBRE DATABASE and we are ready to do a WRITE NEW RECORD command in it.
As CALIBRE seems to use a SERIAL KEY to INDEX the book records we should be able to use it. Asuming all records are new, it would be enough with a numeric variable to do the job, which we will increase by one in every loop.



NumericValue_of_FirstRecord_to_Add%%=100

CREATE NEW BLANK RECORD in DATABASE

KeySerialIndex.CALIBREDATABASE= NumericValue_of_FirstRecord_to_Add%%
Name.CALIBREDATABASE="Jules"
Surname.CALIBREDATABASE="Verne"
...
Cover.CALIBREDATABASE="C:\MYCOVERS\20000leaguescov er.JPG"

STORE NEW RECORD in DATABASE

And that is it. We only have to work the LOOP down, reading the following ASCII lines, chop each line in its fields,
create a new BLANK RECORD in CALIBRE, store the field values in each field and save the new record; until we reach the EOF (END OF FILE) in the ASCII input file.

Lets close the ASCII INPUT FILE and the CALIBRE DATABASE OUTPUT FILE.


Could you please be so kind to write the half a dozen python sentences needed to make the program, just enuogh for me to catch the "programming feeling" for starters. I will need also the database definition of the CALIBRE ebook database, and the commands needed for OPENING, CREATING NEW RECORDS, FIELD VALUE LOADING, STORING NEW RECORDS, CLOSING DATABASE, etc...

I know it is a little to much but I promise to be a good pupil and after having a first workable 0.1 version, I'll work to deliver something more useful to the general public.

Thanks in advance.
LARdT is offline   Reply With Quote