More time fixes
[planet-ucc.git] / XMLWriter.py
index 1311fb6..5b0582e 100644 (file)
@@ -60,7 +60,8 @@ class Planet:
                                if lastItem == None:
                                        break
                                # this checks to see if it's a new day
-                               if time.localtime(lastItem.itemDate) != lastDate:
+                               if time.gmtime(lastItem.itemDate)[6] != lastDate:
+                                       lastDate        = time.gmtime(lastItem.itemDate)[6]
                                        workingDate     = PlanetDate(lastItem.itemDate)
                                        self.dates.append(workingDate)
                                # append the item to the current date
@@ -71,10 +72,12 @@ class Planet:
 
 class XMLWriter:
        def __init__(self, doctype, bloglist):
+               self.blogs      = bloglist
                self.planet     = Planet(bloglist)
                self.items      = self.planet.sort()
                # doctype should be something like XMLWriter.XHTMLWriter
-               self.writer     = doctype(self.items)
+               self.writer             = doctype(self.items)
+               self.writer.parent      = self
        
        def write(self):
                output          = self.writer.write()
@@ -83,18 +86,22 @@ class XMLWriter:
 class XHTMLWriter:
        def __init__(self, planet):
                self.planet     = planet
-               self.maxitems   = 100
+               self.maxitems   = 50
+               self.parent     = None
        
        def __write_item__(self, item):
                output  =       ''
-               output  +=      '<div id="item">\n'
+               output  +=      '<div class="item">\n'
                output  +=      '<h2>%s: %s</h2>\n' % (item.blogTitle, item.itemTitle)
                output  +=      '<p class="time">\n'
-               output  +=      '(%s)\n' % time.strftime('%A %B %d, %Y %H:%M %Z', time.localtime(item.itemDate))
+               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 UTC', time.gmtime(item.itemDate)))
                output  +=      '</p>\n'
                output  +=      '<p class="body">\n'
                output  +=      item.contents
                output  +=      '\n</p>\n'
+               output  +=      '</div>\n'
                return output
        
        def write(self):
@@ -105,12 +112,35 @@ class XHTMLWriter:
                output  +=      '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >\n'
                output  +=      '<head>\n'
                output  +=      '<title>Planet UCC</title>\n'
-               # XXX: we'll want a style sheet in here
+               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  +=      '</head>\n'
                output  +=      '<body>\n'
-               # XXX: we want some stuff in here, I'm sure
+               output  +=      '<div class="header">\n'
+               try:
+                       output  +=      open('header.html').read()
+               except:
+                       pass
+               output  +=      '</div>\n'
+               output  +=      '<div class="sidebar">\n'
+               try:
+                       output  +=      open('sidebar.html').read()
+               except:
+                       pass
+               output  +=      '<h2>Last Updated</h2>\n'
+               output  +=      '<p>\n'
+               output  +=      '%s\n' % time.strftime('%A %B %d, %Y %H:%M UTC', time.gmtime())
+               output  +=      '</p>\n'
+               if self.parent:
+                       output  +=      '<h2>Feeds</h2>\n'
+                       output  +=      '<p>\n'
+                       for blog in self.parent.blogs:
+                               output  += '<a href="%s">%s</a><br />\n' % (blog.blogURL, blog.blogTitle)
+                       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))
+                       output  += '<h1>%s</h1>\n' % time.strftime('%A %B %d, %Y', time.gmtime(date.planetDate))
                        for item in date.items:
                                output  += self.__write_item__(item)
                                # see how many items we've written
@@ -120,7 +150,13 @@ class XHTMLWriter:
                        # again, check to see if we've written the maximum number of items
                        if itemcount >= self.maxitems:
                                break
-               # XXX: we want further stuff here
-               output  +=      '</body>'
+               output  +=      '</div>\n'
+               output  +=      '<div class="footer">\n'
+               try:
+                       output  +=      open('footer.html').read()
+               except:
+                       pass
+               output  +=      '</div>\n'
+               output  +=      '</body>\n'
                output  +=      '</html>'
                return output

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