Writes out a file (if anything changed)
[minutes-rss.git] / minutes-rss.py
index 12c410c..2b31f23 100755 (executable)
@@ -60,15 +60,26 @@ def itemWriter(minutes):
        output += '</item>\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()
+if __name__ == '__main__':
+       xmlpath = os.path.join(MINUTESPATH, 'minutes.xml')
+       try:
+               lastupdate = os.stat(xmlpath)[-2]
+       except OSError:
+               lastupdate = 0
 
-minutes = [UCCMinutes(x) for x in items]
+       # 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()
 
-print RSS(''.join([itemWriter(x) for x in minutes]), minutes[0].modtime)
+       items = [os.path.abspath(x.split(' ')[-1]) for x in items[-15:]]
+       items.reverse()
+
+       latestItem = UCCMinutes(items[0])
+
+       if latestItem.stattime > lastupdate:
+               minutes = [latestItem] + [UCCMinutes(x) for x in items[1:]]
+               output = RSS(''.join([itemWriter(x) for x in minutes]), minutes[0].modtime)
+               open(xmlpath, 'w').write(output)

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