View Single Post
Old 02-12-2009, 01:29 PM   #3
kevin_boone
Enthusiast
kevin_boone began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Feb 2009
Device: prs-505
Well, I threw something together in Python that seems to do the trick. It just runs a lump of SQL and mixes up the results with HTML. Attached, in case anybody's interested. I've never written Python before, so it's doubtless a bit crude. But it works for me.

The output can be passed through html2rtf

html2lrf --add-chapters-to-toc --chapter-attr=h2,none, --page-break-before-tag=$ --author="aaa" --title="aaa index" aaa_index.html

to create an LRF. Naming the author and title `aaa' means that the file will show up on the top of all the lists on the PRS.

As you say, it's of limited usefulness, because you can't do `real' navigation. But I find it helpful to have an indexed list of all books in one place, particularly if I include the summaries from the metadata..

Is there a way to add functionality to Calibre other than building the whole thing from source? Some sort of plug-in system? I'd like to add a feature to build an index file on the PRS every time I add or remove files, but I don't think I have time to learn enough about Calibre to put it into the code proper. Not without breaking it, anyhow

==================
Code:
#!/usr/bin/python

from sqlite3 import dbapi2 as sqlite

connection = sqlite.connect('/media/ebooks_calibre/metadata.db')

cursor = connection.cursor()

cursor.execute('SELECT id,name FROM authors ORDER BY name')

i = 0
author_ids = []
firstletter = ''
for row in cursor:
  id = str(row[0])
  name = row[1]
  if (name[0] != firstletter) :
    firstletter = name[0];
    print "<h2>" + firstletter + "</h2>";
  print "<a href=\"#author_" + id + "\">" + name + "</a><br>\n";
  author_ids.append(row[0]);
  i = i + 1;

for author_id in author_ids:
  print "<a name=\"#author_" + str(author_id) + "\"></a>"
  firstrow = 1;
  cursor.execute('SELECT books.title,authors.name,comments.text FROM authors,books,books_authors_link,comments WHERE books.id=books_authors_link.book AND comments.book=books.id AND authors.id=books_authors_link.author AND books_authors_link.author=' + str(author_id))
  for row in cursor:
    if (firstrow == 1) :
      print "<h3 id=\"author_" + str(author_id) + "\">"
      print row[1]
      print "</h3>"
      print "<br/>"
      firstrow = 0
    print "<b>"
    print row[0]
    print "</b><br/>"
    print " "
    print row[2].encode("utf-8")
    print " "
    print "<p>&nbsp;</p>"

Last edited by kevin_boone; 02-12-2009 at 01:32 PM.
kevin_boone is offline   Reply With Quote