See ChangeLog
[planet-ucc.git] / RSS2Writer.py
diff --git a/RSS2Writer.py b/RSS2Writer.py
new file mode 100644 (file)
index 0000000..86bfbb0
--- /dev/null
@@ -0,0 +1,41 @@
+import time
+
+class RSS2Writer:
+       def __init__(self, planet):
+               self.planet     = planet
+               self.maxitems   = 50
+               self.parent     = None
+       
+       def __write_item__(self, item):
+               output  =       ''
+               output  +=      '<item>\n'
+               output  +=      ' <title>%s: %s</title>\n' % (item.blogTitle, item.itemTitle)
+               output  +=      ' <guid>%s</guid>\n' % item.itemURL
+               output  +=      ' <link>%s</link>\n' % item.itemURL
+               output  +=      ' <description>\n'
+               output  +=      item.contents
+               output  +=      '\n </description>\n'
+               output  +=      '<pubDate>%s</pubDate>\n' % time.strftime('%a, %d %b %Y %H:%M:%S +0000', time.gmtime(item.itemDate))
+               output  +=      '</item>\n'
+               return output
+       
+       def write(self):
+               itemcount       = 0
+               output  =       ''
+               output  +=      '<rss version="2.0">\n'
+               output  +=      ' <channel>\n'
+               output  +=      '  <title>Planet UCC</title>\n'
+               output  +=      '  <link>http://planet.ucc.asn.au/</link>\n'
+               output  +=      '  <language>en</language>\n'
+               output  +=      '  <description>Planet UCC</description>\n'
+               for date in self.planet:
+                       for item in date.items:
+                               output  += self.__write_item__(item)
+                               itemcount += 1
+                               if itemcount >= self.maxitems:
+                                       break
+                       if itemcount >= self.maxitems:
+                               break
+               output  +=      ' </channel>\n'
+               output  +=      '</rss>\n'
+               return output

UCC git Repository :: git.ucc.asn.au