-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (26 loc) · 948 Bytes
/
main.py
File metadata and controls
39 lines (26 loc) · 948 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
36
37
38
39
import sys
from stats import count_words, count_characters, sort_dictionaries
def get_book_text(path):
with open(path) as f:
file_contents = f.read()
return file_contents
def main():
if len(sys.argv) < 2:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
path = sys.argv[1]
print("============ BOOKBOT ============")
print(f"Analyzing book found at {path}...")
content = get_book_text(path)
num_words = count_words(content)
print("----------- Word Count ----------")
print(f"Found {num_words} total words")
count_char = count_characters(content)
sorted_count_char = sort_dictionaries(count_char)
print("--------- Character Count -------")
for x in sorted_count_char:
for key, value in x.items():
if(key.isalpha() ):
print(f"{key}: {value}")
print("============= END ===============")
main()