571998c837634bffbcd3550fb38c15fb856ff11c
[planet-ucc.git] / RSS1Writer.py
1 #
2 # RSS1Writer
3 #
4 # A plugin to XMLWriter to output RSS version 1.0.
5 # This plugin has been developed with no regard for the RSS1.0 spec.
6 #
7 # (c) 2004, Davyd Madeley <[email protected]>
8 #
9
10 import time
11
12 class RSS1Writer:
13         def __init__(self, planet):
14                 self.planet     = planet
15                 self.maxitems   = 50
16                 self.parent     = None
17         
18         def __write_item__(self, item):
19                 output  =       ''
20                 output  +=      '<item rdfAbout="%s">\n' % item.itemURL
21                 output  +=      ' <title>%s: %s</title>\n' % (item.blogTitle, item.itemTitle)
22                 output  +=      ' <link>%s</link>\n' % item.itemURL
23                 output  +=      ' <content:encoded>\n'
24                 output  +=      item.contents
25                 output  +=      '\n </content:encoded>\n'
26                 output  +=      ' <dc:date>%s</dc:date>\n' % time.strftime('%Y-%m-%dT%H:%M:%S+00:00', time.gmtime(item.itemDate))
27                 output  +=      '</item>\n'
28                 return output
29         
30         def write(self):
31                 itemcount       = 0
32                 output  =       '<rss version="1.0\n'
33                 output  +=      ' xmlns:dc="http://purl.org/dc/elements/1.1/"\n'
34                 output  +=      ' xmlns:content="http://purl.org/rss/1.0/modules/content/">\n'
35                 output  +=      ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n'
36                 output  +=      '<rdf:RDF>\n'
37                 output  +=      ' <channel>\n'
38                 output  +=      '  <title>Planet UCC</title>\n'
39                 output  +=      '  <link>http://planet.ucc.asn.au/</link>\n'
40                 output  +=      '  <items>\n'
41                 output  +=      '   <rdf:Seq>\n'
42                 for blog in self.parent.blogs:
43                         output  +=      '    <rdf:li rdf:resource="%s" />\n' % blog.feedURL
44                 output  +=      '   </rdf:Seq>\n'
45                 output  +=      '  <items>\n'
46                 output  +=      ' </channel>\n'
47                 for date in self.planet:
48                         for item in date.items:
49                                 output  += self.__write_item__(item)
50                                 itemcount += 1
51                                 if itemcount >= self.maxitems:
52                                         break
53                         if itemcount >= self.maxitems:
54                                 break
55                 output  +=      '</rdf:RDF>\n'
56                 output  +=      '</rss>'
57                 return output

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