-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (22 loc) · 860 Bytes
/
main.py
File metadata and controls
27 lines (22 loc) · 860 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
from stats import count_words, count_chars, sort_char_count
import sys
if len(sys.argv) != 2:
print ("Usage: python3 main.py <path_to_book>")
sys.exit(1)
def get_book_text(filename):
content_str = filename.read()
return content_str
def main(book_path):
with open(book_path) as f:
booktext = get_book_text(f)
print("============ BOOKBOT ============")
print(f"Analyzing book found at {book_path}...")
print("----------- Word Count ----------")
print(count_words(booktext))
print("--------- Character Count -------")
result_chars_dict = count_chars(booktext)
sorted_chars_dict = sort_char_count(result_chars_dict)
for dict in sorted_chars_dict:
print(f'{dict["name"]}: {dict["num"]}')
print("============= END ===============")
main(sys.argv[1])