feedlist: add new blogs
[planet-ucc.git] / XHTMLWriter.py
index 0694064..838aae8 100644 (file)
@@ -1,4 +1,13 @@
+#
+# XHTMLWriter
+#
+# A plugin to XMLWriter to output XHTML
+#
+# (c) 2004, Davyd Madeley <[email protected]>
+#
+
 import time
+import sys
 
 class XHTMLWriter:
        def __init__(self, planet):
@@ -7,18 +16,27 @@ class XHTMLWriter:
                self.parent     = None
        
        def __write_item__(self, item):
-               output  =       ''
-               output  +=      '<div class="item">\n'
-               output  +=      '<h2>%s: %s</h2>\n' % (item.blogTitle, item.itemTitle)
-               output  +=      '<p class="time">\n'
+               try:
+                       blogTitle, blogName, itemTitle = map(unicode, [item.blogTitle, item.blogName, item.itemTitle])
+               except UnicodeDecodeError, e:
+                       print >> sys.stderr, "Unicode error in %s" % item.itemURL
+                       print >> sys.stderr, e
+                       return ''
+
+               output  =       u''
+               output  +=      u'<div class="item">\n'
+               output  +=      u'<h2><a href="%s" title="%s">%s</a>: <a href="%s">%s</a></h2>\n' % (item.blogURL, blogTitle, blogName, item.itemURL, itemTitle)
+               output  +=      u'<p class="time">\n'
                if item.imageURL:
-                       output += '<a class="image" href="%s"><img class="image" src="%s" alt="%s" /></a>\n' % (item.imageLink, item.imageURL, item.blogTitle)
-               output  +=      '(<a href="%s">%s</a>)\n' % (item.itemURL ,time.strftime('%A %B %d, %Y %H:%M AWST', time.localtime(item.itemDate)))
-               output  +=      '</p>\n'
-               output  +=      '<p class="body">\n'
+                       output += u'<a class="image" href="%s"><img class="image" src="%s" alt="%s" /></a>\n' % (item.imageLink, item.imageURL, item.blogName)
+               output  +=      u'(<a href="%s">%s</a>)\n' % (item.itemURL ,time.strftime('posted on %A %B %d, %Y at %H:%M AWST', time.localtime(item.itemDate)))
+               output  +=      u'</p>\n'
+               output  +=      u'<div class="itembody">\n'
                output  +=      item.contents
-               output  +=      '\n</p>\n'
-               output  +=      '</div>\n'
+               output  +=      u'\n</div>\n'
+               if item.commentsURL:
+                       output += u'<p class="comments"><a href="%s">Comments</a></p>' % item.commentsURL
+               output  +=      u'</div>\n'
                return output
        
        def write(self):
@@ -31,6 +49,9 @@ class XHTMLWriter:
                output  +=      '<title>Planet UCC</title>\n'
                output  +=      '<link rel="stylesheet" href="planet.css" type="text/css" media="screen" />\n'
                output  +=      '<link rel="icon" type="image/png" href="icon.png" />\n'
+               output  +=      '<link rel="SHORTCUT ICON" type="image/png" href="icon.png" />\n'
+               output  +=      '<link rel="alternate" type="application/rss+xml" title="RSS 1.0" href="rss1.xml" />\n'
+               output  +=      '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss2.xml" />\n'
                output  +=      '</head>\n'
                output  +=      '<body>\n'
                output  +=      '<div class="header">\n'
@@ -39,6 +60,19 @@ class XHTMLWriter:
                except:
                        pass
                output  +=      '</div>\n'
+               output  +=      '<div class="items">\n'
+               for date in self.planet:
+                       output  += '<h1>%s</h1>\n' % time.strftime('%A %B %d, %Y', time.localtime(date.planetDate))
+                       for item in date.items:
+                               output  += self.__write_item__(item)
+                               # see how many items we've written
+                               itemcount += 1
+                               if itemcount >= self.maxitems:
+                                       break
+                       # again, check to see if we've written the maximum number of items
+                       if itemcount >= self.maxitems:
+                               break
+               output  +=      '</div>\n'
                output  +=      '<div class="sidebar">\n'
                try:
                        output  +=      open('sidebar.html').read()
@@ -54,22 +88,9 @@ class XHTMLWriter:
                        blogscopy       = self.parent.blogs + []
                        blogscopy.sort(self.__blog_sort__)
                        for blog in blogscopy:
-                               output  += '<a href="%s">%s</a> (<a href="%s">feed</a>)<br />\n' % (blog.blogURL, blog.blogTitle, blog.feedURL)
+                               output  += '<a href="%s">%s</a> (<a href="%s">feed</a>)<br />\n' % (blog.blogURL, blog.blogName, blog.feedURL)
                        output  +=      '</p>\n'
                output  +=      '</div>\n'
-               output  +=      '<div class="items">\n'
-               for date in self.planet:
-                       output  += '<h1>%s</h1>\n' % time.strftime('%A %B %d, %Y', time.localtime(date.planetDate))
-                       for item in date.items:
-                               output  += self.__write_item__(item)
-                               # see how many items we've written
-                               itemcount += 1
-                               if itemcount >= self.maxitems:
-                                       break
-                       # again, check to see if we've written the maximum number of items
-                       if itemcount >= self.maxitems:
-                               break
-               output  +=      '</div>\n'
                output  +=      '<div class="footer">\n'
                try:
                        output  +=      open('footer.html').read()
@@ -81,7 +102,8 @@ class XHTMLWriter:
                return output
        
        def __blog_sort__(self, blog1, blog2):
-               name1, name2    = blog1.blogTitle.split(' ')[-1], blog2.blogTitle.split(' ')[-1]
+               # name1, name2  = blog1.blogName.split(' ')[-1], blog2.blogName.split(' ')[-1]
+               name1, name2 = blog1.blogName, blog2.blogName
                if name1 < name2: return -1
                if name1 == name2: return 0
                if name1 > name2: return 1

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