Thank you all for your help! After a few hours studying I have the following (which I know, is horrible, but it works):
Code:
#import os for executing commands
import os
#import BeautifulSoup
from BeautifulSoup import BeautifulStoneSoup
#define file to use
file = open('/home/michelle/ebookcollection.xml')
#soup it
soup = BeautifulStoneSoup(file)
#read all entries into an array books
for book in soup.fetch('entry'):
#set book title
bookTitle = book.title.string
#set book file
bookFile = book.file.string
bookFile = bookFile.replace('%20', ' ')
bookFile = bookFile.replace('%27','\'')
#determine if book is part of series and set requisite values
bookSeries=""
bookSeriesIndex=""
if book.series is not None:
bookSeries=book.series.string
if book.series_num is not None:
bookSeriesIndex=book.series_num.string
#if book has description, set that as well
bookComment = ""
if book.comments is not None:
bookComment=book.comments.string
bookAuthors = ""
bookTags = "Unread, Tellico"
for a in book.fetch('author'):
thisAuthor = a.string
if thisAuthor.find(",") > -1:
firstName = thisAuthor[(thisAuthor.find(",") + 2):]
lastName = thisAuthor[:thisAuthor.find(",")]
thisAuthor = firstName + " " + lastName
bookAuthors = bookAuthors + thisAuthor +", "
bookAuthors = bookAuthors.strip(", ")
print "Title: " + bookTitle
print "Authors: " + bookAuthors
print "File: " + bookFile
print "Series: " + bookSeries
print "Series Number: " + bookSeriesIndex
print "Description: " + bookComment
print "Tags: " + bookTags
#write it out
command = "epub-meta -t \"" + bookTitle + "\" -a \"" + bookAuthors + "\" --comment=\"" + bookComment + "\" --series=\"" + bookSeries + "\" --series-index=\"" + bookSeriesIndex +"\" --tags=\"" + bookTags + "\" \"" + bookFile + "\""
os.system(command)
There are only two things I haven't been able to figure out how to write to the metadata yet: the ISBN number, and the cover. epub-meta seems to be able to read the ISBN number and extract the cover, but not set either of them. The cover isn't a big deal, but I'd really like to be able to set the ISBN number. I suspect that this may be part of reason kovid suggested using calibredb to add them directly, but, as I understand it, I'd have to use the xml file to create temporary opf files for each book to use for the set_metadata part, and I'm afraid that goes well beyond my python coding abilities...is there a simpler way of doing this?