-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (25 loc) · 897 Bytes
/
Copy pathmain.py
File metadata and controls
33 lines (25 loc) · 897 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
29
30
31
32
33
import sys
from stats import get_num_words, get_char_distribution, sort_distribution
def get_book_text(path):
with open(path) as f:
file_contents = f.read()
return file_contents
def main(book):
content = get_book_text(book)
num_words = get_num_words(content)
char_distrib = get_char_distribution(content)
sorted = sort_distribution(char_distrib)
print("============ BOOKBOT ============")
print(f"Analyzing book found at {book}...")
print("----------- Word Count ----------")
print(f"Found {num_words} total words")
print("--------- Character Count -------")
for d in sorted:
if d["char"].isalpha():
print(f"{d["char"]}: {d["num"]}")
print("============= END ===============")
if len(sys.argv) != 2:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
book = sys.argv[1]
main(book)