-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (27 loc) · 914 Bytes
/
Copy pathmain.py
File metadata and controls
35 lines (27 loc) · 914 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
34
35
from stats import get_word_count
from stats import get_character_counts
from stats import sort_char_counts
import sys
def get_book_text(file_path):
with open(file_path) as f:
file_contents = f.read()
return file_contents
def main():
file = ""
if len(sys.argv) == 2:
file = str(sys.argv[1])
else:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
word_count = get_word_count((get_book_text(file)))
char_dict = get_character_counts(get_book_text(file))
char_list = sort_char_counts(char_dict)
print(f'''============ BOOKBOT ============
Analyzing book found at {file}...
----------- Word Count ----------
Found {word_count} total words
--------- Character Count -------''')
for i in range(0, len(char_list)):
print(f"{char_list[i]["char"]}: {char_list[i]["num"]}")
print("============= END ===============")
main()