-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapterWords.py
More file actions
35 lines (28 loc) · 1.13 KB
/
ChapterWords.py
File metadata and controls
35 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import string
import re
import sys
import argparse
import coreUtils
def chapterWordCounts(path, writeTo):
contents = coreUtils.FileTools.read_data(path)
chapters = coreUtils.ChapterTools.split_and_clean_chapters(contents)
chapterWords = []
for chp in chapters:
chapterWords.append(coreUtils.WordCountTools.simplified_word_count(chp))
ous = chWCFormatting(chapterWords).strip()
coreUtils.FileTools.write_data(ous, writeTo)
# Our output formatting
def chWCFormatting(chapterCounts):
total = 0
oup = ""
for k in range(len(chapterCounts)):
currCount = chapterCounts[k]
total = total + currCount
oup = oup + "\nChapter " + str(k+1) + " has " + str(currCount) + " words. So far there have been a total of " + str(total) + " words."
return oup
# Setting up command line options
parser = argparse.ArgumentParser()
parser.add_argument('file', type=str, help='The html file to process')
parser.add_argument('-o', '--output', type=str, default='oup.txt', required=False, help='The output file to write to. Default=oup.txt')
args = parser.parse_args()
chapterWordCounts(args.file, args.output)