Browse Source

Cleaned up argument parsing

pull/2/head
Dmytro Yeroshkin 1 month ago
parent
commit
5df3a48f35
  1. 36
      novel_stats/novel_stats.py

36
novel_stats/novel_stats.py

@ -1,10 +1,9 @@
#!/usr/bin/python
import argparse
import collections
import sys
import tempfile
import argparse
CHAPTER_MARKER = '## '
STATUS_MARKER = '[status]: # '
@ -28,13 +27,30 @@ def count_words(line):
def main():
# Better argument parsing
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--chapter', action='store_true')
parser.add_argument('-a', '--act', action='store_true')
parser.add_argument('-pp', action='store_true')
parser.add_argument('filename')
parser.add_argument(
'-c',
'--chapter',
action='store_true',
help='output chapter-by-chapter breakdown of word counts, including how many words in each chapter are tagged with which status',
)
parser.add_argument(
'-a',
'--act',
action='store_true',
help='output act-by-act breakdown of word counts (total only)',
)
parser.add_argument(
'-pp',
action='store_true',
help='run markdown pre-processor, this allows for a multi-file input (e.g. each chapter in its own file), but requires the MarkdownPP python library',
)
parser.add_argument(
'markdown_file',
type=argparse.FileType('r'),
help='The markdown file for the novel, main file if a multi-file novel',
)
arguments = parser.parse_args()
filename = arguments.filename
mdfile = None
if arguments.pp:
@ -43,10 +59,12 @@ def main():
import MarkdownPP
mdfile = tempfile.TemporaryFile(mode='w+')
MarkdownPP.MarkdownPP(input=open(filename), output=mdfile, modules=list(MarkdownPP.modules))
MarkdownPP.MarkdownPP(
input=arguments.markdown_file, output=mdfile, modules=list(MarkdownPP.modules)
)
mdfile.seek(0)
else:
mdfile = open(filename)
mdfile = arguments.markdown_file
chapter_heading = None
act_heading = None

Loading…
Cancel
Save