From 86ce18f8d594ea2233cefa2d382c5f5e7df5fb44 Mon Sep 17 00:00:00 2001 From: James French Date: Thu, 12 Aug 2010 22:32:27 +0800 Subject: [PATCH] Initial Commit --- minutes-rss.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 minutes-rss.py diff --git a/minutes-rss.py b/minutes-rss.py new file mode 100755 index 0000000..12c410c --- /dev/null +++ b/minutes-rss.py @@ -0,0 +1,74 @@ +#!/usr/bin/python + +# UCC Minutes Arse (RSS) generator + +import subprocess +import shlex +import os +import time +from cgi import escape +import sys + +MINUTESURL = 'http://www.ucc.asn.au/infobase/minutes/' +MINUTESPATH = '/services/http/infobase/minutes/' + +def RFCTime(pubtime): + return time.strftime("%a, %d %b %Y %H:%M:%S +0800", pubtime) + +class UCCMinutes: + '''Loads relevant information out of UCC minutes''' + def __init__(self, path): + if os.path.exists(path): + self.stattime = os.stat(path)[-2] + self.modtime = RFCTime(time.localtime(self.stattime)) + f = open(path,'r') + self.body = escape(f.read()) + f.close() + + self.title = self.body.split('\n')[0].strip() + + webpath = path.split('/')[-2:] + self.url = MINUTESURL + '/'.join(webpath) + +def RSS(items,pubtime=''): + pubtime = pubtime or RFCTime(time.localtime()) + output = ''' + + + + UCC Meeting Minutes + http://www.ucc.asn.au/infobase/minutes/ + Meeting Minutes of the University Computer Club +''' + output += ' %s\n'%pubtime + output += ''' The giant hack that is Python by JCF + The University Computer Club <committee@ucc.gu.uwa.edu.au> + +''' + output += items + output += '\n' + + return output + +def itemWriter(minutes): + output = '\n' + output += '%s\n'%minutes.url + output += '%s\n'%minutes.title + output += '%s\n'%minutes.modtime + output += '%s\n'%minutes.url + output += '%s]]>\n'%minutes.body + output += '\n' + return output + +# BEWARE THE GIANT HACK - This should be replaced before it burns someone +args = shlex.split('/usr/bin/find %s'%MINUTESPATH + ' -maxdepth 2 -iname "*txt" -type f -printf "%TY-%Tm-%Td %TT %p\n"') +sub = subprocess.Popen(args, stdout=subprocess.PIPE) +items = sub.communicate()[0].split('\n') +items.sort() + +items = [os.path.abspath(x.split(' ')[-1]) for x in items[-15:]] +items.reverse() + +minutes = [UCCMinutes(x) for x in items] + +print RSS(''.join([itemWriter(x) for x in minutes]), minutes[0].modtime) -- 2.20.1