diff decoupage/formats.py @ 60:cf18ea0313f9

add some RSS
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 21 Nov 2010 17:00:02 -0800
parents 07cf168aa98c
children 262fb90a54b4
line wrap: on
line diff
--- a/decoupage/formats.py	Sun Nov 21 13:23:34 2010 -0800
+++ b/decoupage/formats.py	Sun Nov 21 17:00:02 2010 -0800
@@ -2,6 +2,9 @@
 pluggable formats for directory listings
 """
 
+import datetime
+import PyRSS2Gen
+from utils import link
 try:
   import json as json
 except ImportError:
@@ -13,7 +16,7 @@
   just (basically) return the data
   """
 
-  def __init__(self, app, foo):
+  def __init__(self, app):
     self.app = app
 
   def __call__(self, request, data):
@@ -34,4 +37,16 @@
     self.cascade = cascade
 
   def __call__(self, request, data):
-    import pdb; pdb.set_trace()
+    items = [ PyRSS2Gen.RSSItem(title=item['name'],
+                                description=item['description'] or item['name'],
+                                pubDate=item['modified'],
+                                guid=PyRSS2Gen.Guid(link(request, item['path'])))
+              for item in data['files'] ]
+    path_link = link(request, data['path'])
+    rss = PyRSS2Gen.RSS2(title=data['title'] or data['path'],
+                         link=path_link,
+                         description=data['title'] or data['path'],
+                         lastBuildDate = datetime.datetime.now(),
+                         items=items
+                         )
+    return 'application/rss+xml', rss.to_xml()