add RSSFormatter, and link to different types from channel_last.tmpl...
--- 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, ))
--- 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
"""
--- 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
--- /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')
+
--- 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;
+}
--- 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 @@
<a href="${h.build_url(urls.channel_last, channel=channel, count=count+50)}" class='more-link'>...More...</a>
<%include file="lines.tmpl" />
+
+<div id="other-formats">
+ Other formats available:<br/>
+ <a href="${h.build_url(urls.channel_last, channel=channel, count=count, type='txt')}">Plaintext</a>
+ | <a href="${h.build_url(urls.channel_last, channel=channel, count=count, type='png')}">PNG</a>
+ | <a href="${h.build_url(urls.channel_last, channel=channel, count=count, type='rss')}">RSS</a>
+</div>