Mercurial > daily-edition
changeset 28:6e2038000082
added dry-run cmdline option
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 03 Jan 2010 09:20:29 -0800 |
parents | 83091b7b3e59 |
children | 6fbd38dd976a |
files | publish_edition.py |
diffstat | 1 files changed, 20 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/publish_edition.py Sun Jan 03 09:16:37 2010 -0800 +++ b/publish_edition.py Sun Jan 03 09:20:29 2010 -0800 @@ -139,7 +139,8 @@ def publish_edition(update_whoisi=False, update_urls=False, - update_articles=False): + update_articles=False, + dry_run=False): if update_whoisi: update_urls = True if update_urls: @@ -170,7 +171,8 @@ people_indexes = [people.index(person) for person in following] wicache.refresh_people(people_indexes) - save(people, WHOISI_FILENAME) + if not dry_run: + save(people, WHOISI_FILENAME) feeds = {} @@ -185,7 +187,8 @@ if update_urls: refresh_urls(feeds=feeds, urls=urls) - save(urls, URLS_FILENAME) + if not dry_run: + save(urls, URLS_FILENAME) articles = load(ARTICLES_FILENAME, {}) @@ -193,7 +196,8 @@ refresh_articles(articles=articles, feeds=feeds, urls=urls) - save(articles, ARTICLES_FILENAME) + if not dry_run: + save(articles, ARTICLES_FILENAME) issues = load(ISSUES_FILENAME, {'urls': {}, 'pub_dates': []}) @@ -207,12 +211,14 @@ for author in filtered_articles: for article in filtered_articles[author]: issues['urls'][article['url']] = issue_id - save(issues, ISSUES_FILENAME) + if not dry_run: + save(issues, ISSUES_FILENAME) - json.dump({'authors': names, 'articles': filtered_articles}, - open(JSON_FILENAME, 'w')) + if not dry_run: + json.dump({'authors': names, 'articles': filtered_articles}, + open(JSON_FILENAME, 'w')) - logging.info('wrote %s (issue #%d).' % (JSON_FILENAME, issue_id)) + logging.info('wrote %s (issue #%d).' % (JSON_FILENAME, issue_id)) parser_options = { ('-w', '--refresh-whoisi',): @@ -232,6 +238,12 @@ help='re-parse feeds', action='store_true', default=False), + + ('-d', '--dry-run',): + dict(dest='dry_run', + help='do not write anything to disk', + action='store_true', + default=False), } if __name__ == '__main__':