Updated list
[planet-ucc.git] / RSS2Writer.py
1 #
2 # RSS2Writer
3 #
4 # A plugin to XMLWriter to output RSS2.
5 #
6 # (c) 2004, Davyd Madeley <[email protected]>
7 #
8
9 import time, cgi
10
11 class RSS2Writer:
12         def __init__(self, planet):
13                 self.planet     = planet
14                 self.maxitems   = 50
15                 self.parent     = None
16         
17         def __write_item__(self, item):
18                 output  =       ''
19                 output  +=      '<item>\n'
20                 output  +=      ' <title>%s: %s</title>\n' % (item.blogTitle, item.itemTitle)
21                 output  +=      ' <link>%s</link>\n' % item.itemURL
22                 output  +=      ' <description>\n'
23                 output  +=      cgi.escape(item.contents)
24                 output  +=      '\n </description>\n'
25                 output  +=      '<pubDate>%s</pubDate>\n' % time.strftime('%a, %d %b %Y %H:%M:%S +0800', time.gmtime(item.itemDate))
26                 output  +=      '</item>\n'
27                 return output
28         
29         def write(self):
30                 itemcount       = 0
31                 output  =       ''
32                 output  +=      '<rss version="2.0">\n'
33                 output  +=      ' <channel>\n'
34                 output  +=      '  <title>Planet UCC</title>\n'
35                 output  +=      '  <link>http://planet.ucc.asn.au/</link>\n'
36                 output  +=      '  <language>en</language>\n'
37                 output  +=      '  <description>Planet UCC</description>\n'
38                 for date in self.planet:
39                         for item in date.items:
40                                 output  += self.__write_item__(item)
41                                 itemcount += 1
42                                 if itemcount >= self.maxitems:
43                                         break
44                         if itemcount >= self.maxitems:
45                                 break
46                 output  +=      ' </channel>\n'
47                 output  +=      '</rss>\n'
48                 return output

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