-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
28 lines (24 loc) · 909 Bytes
/
main.py
File metadata and controls
28 lines (24 loc) · 909 Bytes
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
from stats import generate_report, get_char_frequency, get_num_words
from sys import argv, exit
def get_book_text(filepath):
with open(filepath) as file:
return file.read()
def main():
if len(argv) != 2:
print("Usage: python3 main.py <path_to_book>")
exit(1)
filepath = argv[1]
book_text = get_book_text(filepath)
num_words = get_num_words(book_text)
char_freq = get_char_frequency(book_text)
report = generate_report(char_freq)
print("============ BOOKBOT ============")
print(f"Analyzing book found at {filepath}...")
print("----------- Word Count ----------")
print(f"Found {num_words} total words")
print("--------- Character Count -------")
for charEntry in report:
if charEntry["char"].isalpha():
print(f"{charEntry['char']}: {charEntry['count']}")
print("============= END ===============")
main()