From 7c1189be656d2ab9f484d9d0f1ab1b8f287de4c8 Mon Sep 17 00:00:00 2001 From: davyd Date: Sat, 6 Mar 2004 06:17:26 +0000 Subject: [PATCH] See ChangeLog some more... more output modules --- Changelog | 6 ++++++ RSS1Writer.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ RSS2Writer.py | 8 ++++++++ XHTMLWriter.py | 8 ++++++++ XMLParse2.py | 2 ++ crontab | 6 +++++- update-planet | 11 +++++++++-- 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 RSS1Writer.py diff --git a/Changelog b/Changelog index 7809779..a6894d0 100644 --- a/Changelog +++ b/Changelog @@ -8,8 +8,14 @@ Moved XHTMLWriter to it's own file, made some API changes. * update-planet Reflected API changes to XMLWriter, added generator for RSS2 feed. + Added generator for RSS1 feed. * crontab Added line to scp rss2.xml to mussel. + Added line to scp rss1.xml to mussel. + * XMLParse2 + Added line to give personalised USER_AGENT. + * Added RSS1Writer.py + Output plugin for RSS1 files. 2004-02-28 ========== diff --git a/RSS1Writer.py b/RSS1Writer.py new file mode 100644 index 0000000..83460d3 --- /dev/null +++ b/RSS1Writer.py @@ -0,0 +1,48 @@ +# +# RSS1Writer +# +# A plugin to XMLWriter to output RSS version 1.0. +# This plugin has been developed with no regard for the RSS1.0 spec. +# +# (c) 2004, Davyd Madeley +# + +import time + +class RSS1Writer: + def __init__(self, planet): + self.planet = planet + self.maxitems = 50 + self.parent = None + + def __write_item__(self, item): + output = '' + output += '\n' % item.itemURL + output += ' %s: %s\n' % (item.blogTitle, item.itemTitle) + output += ' %s\n' % item.itemURL + output += ' \n' + output += item.contents + output += '\n \n' + output += ' %s\n' % time.strftime('%Y-%m-%dT%H:%M:%S+00:00', 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' + # XXX: we need to output the blogroll here + output += ' \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' + return output diff --git a/RSS2Writer.py b/RSS2Writer.py index 86bfbb0..848f78e 100644 --- a/RSS2Writer.py +++ b/RSS2Writer.py @@ -1,3 +1,11 @@ +# +# RSS2Writer +# +# A plugin to XMLWriter to output RSS2. +# +# (c) 2004, Davyd Madeley +# + import time class RSS2Writer: diff --git a/XHTMLWriter.py b/XHTMLWriter.py index 0694064..3ef84c9 100644 --- a/XHTMLWriter.py +++ b/XHTMLWriter.py @@ -1,3 +1,11 @@ +# +# XHTMLWriter +# +# A plugin to XMLWriter to output XHTML +# +# (c) 2004, Davyd Madeley +# + import time class XHTMLWriter: diff --git a/XMLParse2.py b/XMLParse2.py index 563a0fa..3a14e2b 100644 --- a/XMLParse2.py +++ b/XMLParse2.py @@ -13,6 +13,8 @@ import CacheHandler sys.path.insert(0, 'extra') import feedparser +feedparser.USER_AGENT = "PlanetUCC/1.0b +http://planet.ucc.asn.au/ %s" % feedparser.USER_AGENT + class Blog: def __init__(self): self.blogTitle = None diff --git a/crontab b/crontab index 9b00ed4..698ca49 100644 --- a/crontab +++ b/crontab @@ -1,2 +1,6 @@ -*/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 +*/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 && \ + scp $HOME/projects/planetucc/rss1.xml planet@mussel.ucc.asn.au:public-html/rss1.xml 2>/dev/null diff --git a/update-planet b/update-planet index c0634bb..91cd899 100755 --- a/update-planet +++ b/update-planet @@ -7,9 +7,12 @@ # (c) 2004, Davyd Madeley # +# standard python modules import sys, codecs +# planetUCC modules import XMLParse2 as XMLParse, XMLWriter, CacheHandler -import XHTMLWriter, RSS2Writer +# planetUCC output plugins +import XHTMLWriter, RSS2Writer, RSS1Writer # step 1: read in the config and check each object from cache cache = CacheHandler.CacheHandler() @@ -46,10 +49,14 @@ try: 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') + +try: + codecs.open('rss1.xml', 'wb', 'utf-8').write(xmlwriter.write(RSS1Writer.RSS1Writer)) +except: + sys.stderr.write('DEBUG: update-planet: could not write rss1.xml, aborting\n') raise -- 2.20.1