3 # UCC Minutes Arse (RSS) generator
11 MINUTESURL = 'http://www.ucc.asn.au/infobase/minutes/'
12 MINUTESPATH = '/services/http/infobase/minutes/'
15 return time.strftime("%a, %d %b %Y %H:%M:%S +0800", pubtime)
18 '''Loads relevant information out of UCC minutes'''
19 def __init__(self, path):
20 if os.path.exists(path):
21 self.stattime = os.stat(path)[-2]
22 self.modtime = RFCTime(time.localtime(self.stattime))
24 self.body = escape(f.read())
27 self.title = self.body.split('\n')[0].strip()
29 webpath = path.split('/')[-2:]
30 self.url = MINUTESURL + '/'.join(webpath)
32 def RSS(items,pubtime=''):
33 pubtime = pubtime or RFCTime(time.localtime())
34 output = '''<?xml version='1.0' encoding='utf-8' ?>
35 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
37 <atom:link href="http://www.ucc.asn.au/infobase/minutes/minutes.xml" rel="self" type="application/rss+xml" />
38 <title>UCC Meeting Minutes</title>
39 <link>http://www.ucc.asn.au/infobase/minutes/</link>
40 <description>Meeting Minutes of the University Computer Club</description>
42 output += ' <lastBuildDate>%s</lastBuildDate>\n'%pubtime
43 output += ''' <generator>The giant hack that is Python by JCF</generator>
48 output += '</channel>\n</rss>'
52 def itemWriter(minutes):
54 output += '<guid>%s</guid>\n'%minutes.url
55 output += '<title>%s</title>\n'%minutes.title
56 output += '<pubDate>%s</pubDate>\n'%minutes.modtime
57 output += '<link>%s</link>\n'%minutes.url
58 output += '<description><![CDATA[<pre>%s</pre>]]></description>\n'%minutes.body
63 if __name__ == '__main__':
64 xmlpath = os.path.join(MINUTESPATH, 'minutes.xml')
66 lastupdate = os.stat(xmlpath)[-2]
70 # BEWARE THE GIANT HACK - This should be replaced before it burns someone
71 args = shlex.split('/usr/bin/find %s'%MINUTESPATH + ' -maxdepth 2 -iname "*txt" -type f -printf "%TY-%Tm-%Td %TT %p\n"')
72 sub = subprocess.Popen(args, stdout=subprocess.PIPE)
73 items = sub.communicate()[0].split('\n')
76 items = [os.path.abspath(x.split(' ')[-1]) for x in items[-15:]]
79 latestItem = UCCMinutes(items[0])
81 if latestItem.stattime > lastupdate:
82 minutes = [latestItem] + [UCCMinutes(x) for x in items[1:]]
83 output = RSS(''.join([itemWriter(x) for x in minutes]), minutes[0].modtime)
84 open(xmlpath, 'w').write(output)