-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (26 loc) · 945 Bytes
/
Copy pathmain.py
File metadata and controls
32 lines (26 loc) · 945 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
from stats import count_words
from stats import count_chars
from stats import sort_char_count
import sys
def get_book_text(file):
return file.read()
def main():
if len(sys.argv) != 2:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
book_source = sys.argv[1]
with open(book_source) as f:
text = get_book_text(f)
num_words = count_words(text)
num_chars = count_chars(text)
sorted_count = sort_char_count(num_chars)
print("============ BOOKBOT ============")
print(f"Analyzing book found at {book_source}...")
print("----------- Word Count ----------")
print(f"Found {num_words} total words")
print("--------- Character Count -------")
for d in sorted_count:
if d["character"].isalpha():
print(f"{d['character']}: {d['count']}")
print("============= END ===============")
main()