From d79e3f5b803616757cd52e6b262c7aff30e549a2 Mon Sep 17 00:00:00 2001 From: Dmytro Yeroshkin Date: Fri, 22 Oct 2021 11:54:19 +0200 Subject: [PATCH] Made chapter/act summaries optional --- novel_stats/novel_stats.py | 42 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/novel_stats/novel_stats.py b/novel_stats/novel_stats.py index 51a10c8..9bae732 100755 --- a/novel_stats/novel_stats.py +++ b/novel_stats/novel_stats.py @@ -79,32 +79,34 @@ def main(): word_count_by_act[act_heading] += word_count_by_chapter[chapter_heading] total_word_count += word_count_by_chapter[chapter_heading] - # Print out word counts. - for chapter_heading, chapter_word_count in word_count_by_chapter.items(): - if chapter_heading is None: - continue + if '-c' in arguments or '--chapter' in arguments: + # Print out word counts. + for chapter_heading, chapter_word_count in word_count_by_chapter.items(): + if chapter_heading is None: + continue + if len(status_by_chapter[chapter_heading]) > 1: + print(f'chapter {chapter_heading}:') - if len(status_by_chapter[chapter_heading]) > 1: - print(f'chapter {chapter_heading}:') + for chapter_status, status_count in status_by_chapter[chapter_heading].items(): + print(f'\t {status_count:,} ({chapter_status})') + print(f'\t {chapter_word_count:,} words (total)') + elif len(status_by_chapter[chapter_heading]) == 1: + chapter_status = list(status_by_chapter[chapter_heading].keys())[0] + print(f'chapter {chapter_heading}: {chapter_word_count:,} ({chapter_status})') + else: + print(f'chapter {chapter_heading}: {chapter_word_count:,}') - for chapter_status, status_count in status_by_chapter[chapter_heading].items(): - print(f'\t {status_count:,} ({chapter_status})') - print(f'\t {chapter_word_count:,} words (total)') - elif len(status_by_chapter[chapter_heading]) == 1: - chapter_status = list(status_by_chapter[chapter_heading].keys())[0] - print(f'chapter {chapter_heading}: {chapter_word_count:,} ({chapter_status})') - else: - print(f'chapter {chapter_heading}: {chapter_word_count:,}') + print() + if '-a' in arguments or '--act' in arguments: + for act_heading, act_word_count in word_count_by_act.items(): + if act_heading is None: + continue - print() + print('act {}: {:,} words (~{}%)'.format(act_heading, act_word_count, act_word_count * 100 // total_word_count)) - for act_heading, act_word_count in word_count_by_act.items(): - if act_heading is None: - continue - - print('act {}: {:,} words (~{}%)'.format(act_heading, act_word_count, act_word_count * 100 // total_word_count)) + print() for status, status_word_count in word_count_by_status.items(): print('{}: {:,} words (~{}%)'.format(status, status_word_count, status_word_count * 100 // total_word_count))