log_formatter_rss.py
author Tero Marttila <terom@fixme.fi>
Wed, 11 Feb 2009 02:07:07 +0200
changeset 93 48fca00689e3
parent 80 a0662cff1d9d
permissions -rw-r--r--
implement scripts/search-index autoload
"""
    Uses PyRSS2Gen to generate XML RSS documents
"""

import PyRSS2Gen as RSS2Gen
import datetime, pytz

class RSSFormatter (object) :
    """
        Mixin for LogFormatter that implements the basic RSS-rendering stuff on top of format_html
    """

    def format_rss (self, lines, **kwargs) :
        """
            Process using format_html
        """
        
        # build the RSS2 object and return the XML
        return RSS2Gen.RSS2(
            title           = "IRC RSS feed",
            link            = "http://irclogs.qmsk.net/",
            description     = "A stupid RSS feed that nobody sane would ever use",
            
            # XXX: GMT
            lastBuildDate   = datetime.datetime.utcnow(),

            items           = [
                RSS2Gen.RSSItem(
                    # use the formatted HTML data as the title
                    title       = html_data,

                    # timestamp
                    pubDate     = line.timestamp.astimezone(pytz.utc),

                    # link
                    link        = "http://xxx/",

                ) for line, html_data in self.format_html(lines, **kwargs)
            ]
        ).to_xml('utf8')