log_formatter_rss.py
author Tero Marttila <terom@fixme.fi>
Sat, 14 Feb 2009 20:13:26 +0200
changeset 128 2a8a190f8aee
parent 80 a0662cff1d9d
permissions -rw-r--r--
fix config.VERSION_LINK to use relpath('.')
80
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
"""
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
    Uses PyRSS2Gen to generate XML RSS documents
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
"""
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
import PyRSS2Gen as RSS2Gen
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
import datetime, pytz
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
class RSSFormatter (object) :
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
    """
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
        Mixin for LogFormatter that implements the basic RSS-rendering stuff on top of format_html
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
    """
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
    def format_rss (self, lines, **kwargs) :
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
        """
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
            Process using format_html
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
        """
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
        
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
        # build the RSS2 object and return the XML
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
        return RSS2Gen.RSS2(
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
            title           = "IRC RSS feed",
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
            link            = "http://irclogs.qmsk.net/",
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
            description     = "A stupid RSS feed that nobody sane would ever use",
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
            
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
            # XXX: GMT
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
            lastBuildDate   = datetime.datetime.utcnow(),
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
            items           = [
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
                RSS2Gen.RSSItem(
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
                    # use the formatted HTML data as the title
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
                    title       = html_data,
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
                    # timestamp
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
                    pubDate     = line.timestamp.astimezone(pytz.utc),
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
                    # link
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
                    link        = "http://xxx/",
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
                ) for line, html_data in self.format_html(lines, **kwargs)
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
            ]
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
        ).to_xml('utf8')
a0662cff1d9d add RSSFormatter, and link to different types from channel_last.tmpl...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41