Initial Commit
[minutes-rss.git] / minutes-rss.py
1 #!/usr/bin/python
2
3 # UCC Minutes Arse (RSS) generator
4
5 import subprocess
6 import shlex
7 import os
8 import time
9 from cgi import escape
10 import sys
11
12 MINUTESURL = 'http://www.ucc.asn.au/infobase/minutes/'
13 MINUTESPATH = '/services/http/infobase/minutes/'
14
15 def RFCTime(pubtime):
16         return time.strftime("%a, %d %b %Y %H:%M:%S +0800", pubtime)
17
18 class UCCMinutes:
19         '''Loads relevant information out of UCC minutes'''
20         def __init__(self, path):
21                 if os.path.exists(path):
22                         self.stattime = os.stat(path)[-2]
23                         self.modtime = RFCTime(time.localtime(self.stattime))
24                         f = open(path,'r')
25                         self.body = escape(f.read())
26                         f.close()
27
28                         self.title = self.body.split('\n')[0].strip()
29
30                         webpath = path.split('/')[-2:]
31                         self.url = MINUTESURL + '/'.join(webpath)
32
33 def RSS(items,pubtime=''):
34         pubtime = pubtime or RFCTime(time.localtime())
35         output = '''<?xml version='1.0' encoding='utf-8' ?>
36 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
37 <channel>
38  <atom:link href="http://www.ucc.asn.au/infobase/minutes/minutes.xml" rel="self" type="application/rss+xml" />
39  <title>UCC Meeting Minutes</title>
40  <link>http://www.ucc.asn.au/infobase/minutes/</link>
41  <description>Meeting Minutes of the University Computer Club</description>
42 '''
43         output += ' <lastBuildDate>%s</lastBuildDate>\n'%pubtime
44         output += ''' <generator>The giant hack that is Python by JCF</generator>
45  <copyright>The University Computer Club &#x3C;[email protected]&#x3E;</copyright>
46
47 '''
48         output += items
49         output += '</channel>\n</rss>'
50
51         return output
52
53 def itemWriter(minutes):
54         output = '<item>\n'
55         output += '<guid>%s</guid>\n'%minutes.url
56         output += '<title>%s</title>\n'%minutes.title
57         output += '<pubDate>%s</pubDate>\n'%minutes.modtime
58         output += '<link>%s</link>\n'%minutes.url
59         output += '<description><![CDATA[<pre>%s</pre>]]></description>\n'%minutes.body
60         output += '</item>\n'
61         return output
62
63 # BEWARE THE GIANT HACK - This should be replaced before it burns someone
64 args = shlex.split('/usr/bin/find %s'%MINUTESPATH + ' -maxdepth 2 -iname "*txt" -type f -printf "%TY-%Tm-%Td %TT %p\n"')
65 sub = subprocess.Popen(args, stdout=subprocess.PIPE)
66 items = sub.communicate()[0].split('\n')
67 items.sort()
68
69 items = [os.path.abspath(x.split(' ')[-1]) for x in items[-15:]]
70 items.reverse()
71
72 minutes = [UCCMinutes(x) for x in items]
73
74 print RSS(''.join([itemWriter(x) for x in minutes]), minutes[0].modtime)

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