# HG changeset patch # User Tero Marttila # Date 1234228963 -7200 # Node ID a0662cff1d9dcddf5fe74f4def784249b5654d7c # Parent 43ac75054d5c73dfbd3be53be42aec2d326a4280 add RSSFormatter, and link to different types from channel_last.tmpl... diff -r 43ac75054d5c -r a0662cff1d9d handlers.py --- a/handlers.py Tue Feb 10 02:57:16 2009 +0200 +++ b/handlers.py Tue Feb 10 03:22:43 2009 +0200 @@ -103,6 +103,12 @@ png_data = formatter.format_png(lines) return http.Response(png_data, 'image/png', charset=None) + + elif type == 'rss' : + # RSS feed + rss_data = formatter.format_rss(lines) + + return http.Response(rss_data, 'application/rss+xml') else : raise http.ResponseError("Unrecognized type: %r" % (type, )) diff -r 43ac75054d5c -r a0662cff1d9d log_formatter.py --- a/log_formatter.py Tue Feb 10 02:57:16 2009 +0200 +++ b/log_formatter.py Tue Feb 10 03:22:43 2009 +0200 @@ -6,6 +6,7 @@ from log_line import LogTypes from log_formatter_pil import PILImageFormatter +from log_formatter_rss import RSSFormatter class LogFormatter (object) : """ @@ -83,11 +84,20 @@ abstract - def format_png (self, lines) : + def format_png (self, lines, full_timestamps=False) : """ Format as a PNG image, returning the binary PNG data """ + abstract + + def format_rss (self, lines, full_timestamps=False) : + """ + Format as an XML RSS document + """ + + abstract + class BaseHTMLFormatter (object) : """ Implements some HTML-formatting utils @@ -111,7 +121,7 @@ return self.URL_REGEXP.sub(_encode_url, line) -class IrssiTextFormatter (PILImageFormatter, LogFormatter) : +class IrssiTextFormatter (RSSFormatter, PILImageFormatter, LogFormatter) : """ Implements format_txt for irssi-style output """ diff -r 43ac75054d5c -r a0662cff1d9d log_formatter_pil.py --- a/log_formatter_pil.py Tue Feb 10 02:57:16 2009 +0200 +++ b/log_formatter_pil.py Tue Feb 10 03:22:43 2009 +0200 @@ -8,7 +8,7 @@ class PILImageFormatter (object) : """ - Implements the basic image-rendering operations on top of format_txt + Mixin for LogFormatter that implements the basic image-rendering operations on top of format_txt """ # the font we load diff -r 43ac75054d5c -r a0662cff1d9d log_formatter_rss.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/log_formatter_rss.py Tue Feb 10 03:22:43 2009 +0200 @@ -0,0 +1,41 @@ +""" + 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') + diff -r 43ac75054d5c -r a0662cff1d9d static/irclogs.css --- a/static/irclogs.css Tue Feb 10 02:57:16 2009 +0200 +++ b/static/irclogs.css Tue Feb 10 03:22:43 2009 +0200 @@ -9,6 +9,10 @@ color: #000000; } +a { + color: #454545; +} + /* * Menu */ @@ -357,3 +361,9 @@ background-color: #d0d0d0; } +/* Lastlog */ +div#other-formats { + font-size: small; + text-align: center; + font-style: italic; +} diff -r 43ac75054d5c -r a0662cff1d9d templates/channel_last.tmpl --- a/templates/channel_last.tmpl Tue Feb 10 02:57:16 2009 +0200 +++ b/templates/channel_last.tmpl Tue Feb 10 03:22:43 2009 +0200 @@ -4,3 +4,10 @@ ...More... <%include file="lines.tmpl" /> + +
+ Other formats available:
+ Plaintext + | PNG + | RSS +