From e6d4f12b0cfee1b4a4b0e5da499c08f7cca702b8 Mon Sep 17 00:00:00 2001 From: James French Date: Thu, 12 Aug 2010 22:45:55 +0800 Subject: [PATCH] Writes out a file (if anything changed) Should add scripts for dealing with cron, will test then push up to UCC for now --- minutes-rss.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/minutes-rss.py b/minutes-rss.py index 12c410c..2b31f23 100755 --- a/minutes-rss.py +++ b/minutes-rss.py @@ -60,15 +60,26 @@ def itemWriter(minutes): 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() +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) -- 2.20.1