-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (32 loc) · 1.11 KB
/
Copy pathmain.py
File metadata and controls
39 lines (32 loc) · 1.11 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
34
35
36
37
38
39
from sys import argv, exit
from stats import get_num_words, get_chars_dict, dict_to_sorted_list
def main():
# print(len(argv))
if len(argv) < 2:
print("Usage: python3 main.py <path_to_book>")
exit(1)
file_path = argv[1]
file_contents = get_book(file_path)
word_count = get_num_words(file_contents)
chars_dict = get_chars_dict(file_contents)
sorted_list = dict_to_sorted_list(chars_dict)
print_report(file_path, word_count, sorted_list)
# print(f"--- Begin report of {file_path} ---")
# print(f"Found {get_num_words(file_contents)} total words ")
# print()
# print_letter_count(file_contents)
# print("-- End report ---")
def get_book(str_path):
with open(str_path) as f:
return f.read()
def print_report(file_path, word_count, chars_sorted_list):
print("============ BOOKBOT ============")
print(f"Analyzing book found at {file_path}...")
print("----------- Word Count ----------")
print(f"Found {word_count} total words ")
print("--------- Character Count -------")
for item in chars_sorted_list:
if item[0].isalpha():
print(f"{item[0]}: {item[1]}")
print("============= END ===============")
main()