import os
import sqlite3

import PyRSS2Gen as rss

def rss_items (db):
  for title, synopsis in db.execute ("SELECT title, synopsis FROM whatsnew ORDER BY date_added DESC LIMIT 20"):
    yield rss.RSSItem (
      title=title,
      link="http://local.goodtoread.org",
      description=synopsis
    )

if __name__ == '__main__':
  rss_channel = rss.RSS2 (
    title=u"goodtoread.org",
    link="http://local.goodtoread.org",
    description="goodtoread.org",
    items=rss_items (sqlite3.connect ("books.db"))
  )
  open ("books.xml", "w").write (rss_channel.to_xml ())

  os.startfile ("books.xml")
11