Updated blog feed address.
[planet-ucc.git] / FOAFWriter.py
1 #
2 # FOAFWriter
3 #
4 # A plugin to XMLWriter to output FOAF (friend of a friend).
5 #
6 # I have a quick look through some sample FOAF, it seems it
7 # can get quite intricate in things it can tell you, however
8 # other Planets only offer this basic feed. Given this is almost
9 # all the information we know, that can't be too bad.
10 #
11 # (c) 2004, Davyd Madeley <[email protected]>
12 #
13
14 class FOAFWriter:
15         def __init__(self, planet):
16                 self.parent     = None
17         
18         def __write_item__(self, blog):
19                 output  =       ''
20                 output  +=      '<foaf:member>\n'
21                 output  +=      ' <foaf:Agent>\n'
22                 output  +=      '  <foaf:name>%s</foaf:name>\n' % blog.blogName
23                 output  +=      '  <foaf:weblog>\n'
24                 output  +=      '   <foaf:Document rdf:about="%s">\n' % blog.blogURL
25                 output  +=      '    <dc:title>%s</dc:title>\n' % blog.blogTitle
26                 output  +=      '    <rdfs:seeAlso>\n'
27                 output  +=      '     <rss:channel rdf:about="%s" />\n' % blog.feedURL
28                 output  +=      '    </rdfs:seeAlso>\n'
29                 output  +=      '   </foaf:Document>\n'
30                 output  +=      '  </foaf:weblog>\n'
31                 output  +=      ' </foaf:Agent>\n'
32                 output  +=      '</foaf:member>\n'
33                 return output
34         
35         def write(self):
36                 itemcount       = 0
37                 output  =       ''
38                 output  +=      '<rdf:RDF>\n'
39                 output  +=      ' xmlns="http://purl.org/rss/1.0/"\n'
40                 output  +=      ' xmlns:dc="http://purl.org/dc/elements/1.1/"\n'
41                 output  +=      ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n'
42                                 # XXX: probably need other doctypes here
43                                 # infact, need to check XML structures
44                 output  +=      ' <foaf:Group>\n'
45                 output  +=      '  <foaf:name>Planet UCC</foaf:name>\n'
46                 output  +=      '  <foaf:homepage>http://planet.ucc.asn.au/</foaf:homepage>\n'
47                 output  +=      '  <rdfs:seeAlso rdf:resource="http://planet.ucc.asn.au/foaf.xml" />\n'
48                 for blog in self.parent.blogs:
49                         output  +=      self.__write_item__(blog)
50                 output  +=      ' </foaf:Group>\n'
51                 output  +=      '</rdf:RDF>'
52                 return output

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