Author: deryck Date: 2004-09-28 05:09:06 +0000 (Tue, 28 Sep 2004) New Revision: 359
WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba-web&path=/trunk/scripts&rev=359&nolog=1 Log: Another pass at date handling for the news script. Don't format date until writing to index.html. This ensures that stories sorted under same heading date are still listed in reverse chronological order. --deryck Modified: trunk/scripts/updateNews.py Changeset: Modified: trunk/scripts/updateNews.py =================================================================== --- trunk/scripts/updateNews.py 2004-09-27 22:22:49 UTC (rev 358) +++ trunk/scripts/updateNews.py 2004-09-28 05:09:06 UTC (rev 359) @@ -61,43 +61,35 @@ all_stories = {} for topic in topics: os.chdir(topic) - topic_stories = {} for file in os.listdir(os.curdir): if file in not_news: continue f_lines = open(file, 'r').readlines() story = "".join(f_lines) + '<div class="reference">Link: <a href="/samba/news/' + topic + '/#' + file[:-5] + '">' + topic + '/</a></div>\n\n' - f_date = time.gmtime(os.stat(file)[ST_MTIME])[:3] - # Temporarily group the topic's stories under date modified - if f_date in topic_stories.keys(): - topic_stories[f_date] += story - else: - topic_stories[f_date] = story - - for h2date in topic_stories.keys(): - # Now lump topic groups into one dict, again sorted by mdate - if h2date in all_stories.keys(): - all_stories[h2date] += topic_stories[h2date] - else: - all_stories[h2date] = topic_stories[h2date] - + f_date = os.stat(file)[ST_MTIME] + all_stories[f_date] = story + os.chdir(top_dir) +post_dates = all_stories.keys() +post_dates.sort() +post_dates.reverse() + index = open('index.html', 'w') index.write('<!--#include virtual="/samba/news/header.html" -->\n') index.write('<title>news.samba.org</title>\n') index.write('<!--#include virtual="/samba/news/header2.html" -->\n\n') index.close() - -post_dates = all_stories.keys() -post_dates.sort() -post_dates.reverse() -for h2date in post_dates: - news_text = all_stories[h2date] +for date in post_dates: + news_text = all_stories[date] + h2date = date_to_str(time.gmtime(date)[:3]) index = open('index.html', 'a') - index.write('<h2>' + date_to_str(h2date) + '</h2>\n\n') - index.write(news_text) + if open('index.html', 'r').read().find(h2date) > -1: + index.write(news_text) + else: + index.write('<h2>' + h2date + '</h2>\n\n') + index.write(news_text) index.close() index = open('index.html', 'a') @@ -116,12 +108,8 @@ for file in filelist: if file in not_news: continue f_lines = open(file, 'r').readlines() - f_date = time.gmtime(os.stat(file)[ST_MTIME])[:3] - # group stories from same date under that one date - if f_date in stories_by_date.keys(): - stories_by_date[f_date].append("".join(f_lines)) - else: - stories_by_date[f_date] = f_lines + f_date = os.stat(file)[ST_MTIME] + stories_by_date[f_date] = f_lines index = open('index.html', 'w') index.write('<!--#include virtual="/samba/news/header.html" -->\n') @@ -135,11 +123,15 @@ post_dates.sort() post_dates.reverse() - for h2date in post_dates: - news_text = "".join(stories_by_date[h2date]) + for date in post_dates: + news_text = "".join(stories_by_date[date]) + h2date = date_to_str(time.gmtime(date)[:3]) index = open('index.html', 'a') - index.write('<h2>' + date_to_str(h2date) + '</h2>\n\n') - index.write(news_text) + if open('index.html', 'r').read().find(h2date) > -1: + index.write(news_text) + else: + index.write('<h2>' + h2date + '</h2>\n\n') + index.write(news_text) index.close() index = open('index.html', 'a')