.gitignore: ignore generated files
[planet-ucc.git] / RSS1Writer.py
1 #
2 # RSS1Writer
3 #
4 # A plugin to XMLWriter to output RSS version 1.0.
5 #
6 # (c) 2004, Davyd Madeley <[email protected]>
7 #
8
9 import time, cgi
10
11 class RSS1Writer:
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 rdfAbout="%s">\n' % item.itemURL
20                 output  +=      ' <title>%s: %s</title>\n' % (item.blogName, 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  +=      ' <dc:date>%s</dc:date>\n' % time.strftime('%Y-%m-%dT%H:%M:%S+08:00', time.gmtime(item.itemDate))
26                 output  +=      '</item>\n'
27                 return output
28         
29         def write(self):
30                 itemcount       = 0
31                 output  =       ''
32                 output  +=      '<rdf:RDF>\n'
33                 output  +=      ' xmlns="http://purl.org/rss/1.0/"\n'
34                 output  +=      ' xmlns:dc="http://purl.org/dc/elements/1.1/"\n'
35                 output  +=      ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n'
36                 output  +=      ' <channel>\n'
37                 output  +=      '  <title>Planet UCC</title>\n'
38                 output  +=      '  <link>http://planet.ucc.asn.au/</link>\n'
39                 output  +=      '  <items>\n'
40                 output  +=      '   <rdf:Seq>\n'
41                 for blog in self.parent.blogs:
42                         output  +=      '    <rdf:li rdf:resource="%s" />\n' % blog.feedURL
43                 output  +=      '   </rdf:Seq>\n'
44                 output  +=      '  </items>\n'
45                 output  +=      ' </channel>\n'
46                 for date in self.planet:
47                         for item in date.items:
48                                 output  += self.__write_item__(item)
49                                 itemcount += 1
50                                 if itemcount >= self.maxitems:
51                                         break
52                         if itemcount >= self.maxitems:
53                                 break
54                 output  +=      '</rdf:RDF>'
55                 return output

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