From 5978ce5ae181d88a687a1eae36bde3513e2d06dd Mon Sep 17 00:00:00 2001 From: davyd Date: Sat, 6 Mar 2004 05:44:48 +0000 Subject: [PATCH] See ChangeLog --- Changelog | 22 ++++++++++++ RSS2Writer.py | 41 +++++++++++++++++++++ XHTMLWriter.py | 87 ++++++++++++++++++++++++++++++++++++++++++++ XMLWriter.py | 97 ++++---------------------------------------------- crontab | 2 +- update-planet | 15 ++++++-- 6 files changed, 170 insertions(+), 94 deletions(-) create mode 100644 RSS2Writer.py create mode 100644 XHTMLWriter.py diff --git a/Changelog b/Changelog index 6279c4a..7809779 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,25 @@ +2004-03-06 +========== + * Added RSS2Writer.py + XMLWriter plugin for handling RSS2 output. + * Added XHTMLWriter.py + Moved XHTMLWriter plugin out of XMLWriter. + * XMLWriter.py + Moved XHTMLWriter to it's own file, made some API changes. + * update-planet + Reflected API changes to XMLWriter, added generator for RSS2 feed. + * crontab + Added line to scp rss2.xml to mussel. + +2004-02-28 +========== + * crontab + Reduced update time to 5 minutes + * planet.css + Tweaked CSS to make sidebar background non-transparent. + * feedlist + Added people. + 2004-02-15 ========== * update-planet diff --git a/RSS2Writer.py b/RSS2Writer.py new file mode 100644 index 0000000..86bfbb0 --- /dev/null +++ b/RSS2Writer.py @@ -0,0 +1,41 @@ +import time + +class RSS2Writer: + def __init__(self, planet): + self.planet = planet + self.maxitems = 50 + self.parent = None + + def __write_item__(self, item): + output = '' + output += '\n' + output += ' %s: %s\n' % (item.blogTitle, item.itemTitle) + output += ' %s\n' % item.itemURL + output += ' %s\n' % item.itemURL + output += ' \n' + output += item.contents + output += '\n \n' + output += '%s\n' % time.strftime('%a, %d %b %Y %H:%M:%S +0000', time.gmtime(item.itemDate)) + output += '\n' + return output + + def write(self): + itemcount = 0 + output = '' + output += '\n' + output += ' \n' + output += ' Planet UCC\n' + output += ' http://planet.ucc.asn.au/\n' + output += ' en\n' + output += ' Planet UCC\n' + for date in self.planet: + for item in date.items: + output += self.__write_item__(item) + itemcount += 1 + if itemcount >= self.maxitems: + break + if itemcount >= self.maxitems: + break + output += ' \n' + output += '\n' + return output diff --git a/XHTMLWriter.py b/XHTMLWriter.py new file mode 100644 index 0000000..0694064 --- /dev/null +++ b/XHTMLWriter.py @@ -0,0 +1,87 @@ +import time + +class XHTMLWriter: + def __init__(self, planet): + self.planet = planet + self.maxitems = 50 + self.parent = None + + def __write_item__(self, item): + output = '' + output += '
\n' + output += '

%s: %s

\n' % (item.blogTitle, item.itemTitle) + output += '

\n' + if item.imageURL: + output += '%s\n' % (item.imageLink, item.imageURL, item.blogTitle) + output += '(%s)\n' % (item.itemURL ,time.strftime('%A %B %d, %Y %H:%M AWST', time.localtime(item.itemDate))) + output += '

\n' + output += '

\n' + output += item.contents + output += '\n

\n' + output += '
\n' + return output + + def write(self): + itemcount = 0 + output = '' + output += '\n' + output += '\n' + output += '\n' + output += '\n' + output += 'Planet UCC\n' + output += '\n' + output += '\n' + output += '\n' + output += '\n' + output += '
\n' + try: + output += open('header.html').read() + except: + pass + output += '
\n' + output += '\n' + output += '
\n' + for date in self.planet: + output += '

%s

\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 += '
\n' + output += '\n' + output += '\n' + output += '' + return output + + def __blog_sort__(self, blog1, blog2): + name1, name2 = blog1.blogTitle.split(' ')[-1], blog2.blogTitle.split(' ')[-1] + if name1 < name2: return -1 + if name1 == name2: return 0 + if name1 > name2: return 1 diff --git a/XMLWriter.py b/XMLWriter.py index 38904dc..7f60c4e 100644 --- a/XMLWriter.py +++ b/XMLWriter.py @@ -71,100 +71,15 @@ class Planet: class XMLWriter: - def __init__(self, doctype, bloglist): + def __init__(self, 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.parent = self - def write(self): - output = self.writer.write() + def write(self, doctype): + # doctype should be something like XHTMLWriter.XHTMLWriter + writer = doctype(self.items) + writer.parent = self + output = writer.write() return output -class XHTMLWriter: - def __init__(self, planet): - self.planet = planet - self.maxitems = 50 - self.parent = None - - def __write_item__(self, item): - output = '' - output += '
\n' - output += '

%s: %s

\n' % (item.blogTitle, item.itemTitle) - output += '

\n' - if item.imageURL: - output += '%s\n' % (item.imageLink, item.imageURL, item.blogTitle) - output += '(%s)\n' % (item.itemURL ,time.strftime('%A %B %d, %Y %H:%M AWST', time.localtime(item.itemDate))) - output += '

\n' - output += '

\n' - output += item.contents - output += '\n

\n' - output += '
\n' - return output - - def write(self): - itemcount = 0 - output = '' - output += '\n' - output += '\n' - output += '\n' - output += '\n' - output += 'Planet UCC\n' - output += '\n' - output += '\n' - output += '\n' - output += '\n' - output += '
\n' - try: - output += open('header.html').read() - except: - pass - output += '
\n' - output += '\n' - output += '
\n' - for date in self.planet: - output += '

%s

\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 += '
\n' - output += '\n' - output += '\n' - output += '' - return output - - def __blog_sort__(self, blog1, blog2): - name1, name2 = blog1.blogTitle.split(' ')[-1], blog2.blogTitle.split(' ')[-1] - if name1 < name2: return -1 - if name1 == name2: return 0 - if name1 > name2: return 1 diff --git a/crontab b/crontab index c05976a..9b00ed4 100644 --- a/crontab +++ b/crontab @@ -1,2 +1,2 @@ -*/5 * * * * cd $HOME/projects/planetucc/ && ./update-planet > /dev/null && scp $HOME/projects/planetucc/planet.html planet@mussel.ucc.asn.au:public-html/index.html 2>/dev/null +*/5 * * * * cd $HOME/projects/planetucc/ && ./update-planet > /dev/null && scp $HOME/projects/planetucc/planet.html planet@mussel.ucc.asn.au:public-html/index.html 2>/dev/null && scp $HOME/projects/planetucc/rss2.xml planet@mussel.ucc.asn.au:public-html/rss2.xml 2>/dev/null diff --git a/update-planet b/update-planet index b532165..c0634bb 100755 --- a/update-planet +++ b/update-planet @@ -9,6 +9,7 @@ import sys, codecs import XMLParse2 as XMLParse, XMLWriter, CacheHandler +import XHTMLWriter, RSS2Writer # step 1: read in the config and check each object from cache cache = CacheHandler.CacheHandler() @@ -37,8 +38,18 @@ for feed in feeds: else: pass -# step 3: write feed to disk +# step 3: sift the feeds +xmlwriter = XMLWriter.XMLWriter(blogs) + +# step 4: write feed to disk try: - codecs.open('planet.html', 'wb', 'utf-8').write(XMLWriter.XMLWriter(XMLWriter.XHTMLWriter, blogs).write()) + codecs.open('planet.html', 'wb', 'utf-8').write(xmlwriter.write(XHTMLWriter.XHTMLWriter)) except: sys.stderr.write('DEBUG: update-planet: could not write planet.html, aborting\n') + raise + +try: + codecs.open('rss2.xml', 'wb', 'utf-8').write(xmlwriter.write(RSS2Writer.RSS2Writer)) +except: + sys.stderr.write('DEBUG: update-planet: could not write rss2.xml, aborting\n') + raise -- 2.20.1