-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (25 loc) · 983 Bytes
/
main.py
File metadata and controls
31 lines (25 loc) · 983 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 number_of_words
from stats import number_of_characters
from stats import sorting
import sys
def get_book_text(filepath):
with open(filepath, encoding='utf-8') as f:
file_contents = f.read()
return file_contents
def main():
if not len(sys.argv) == 2:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
entire_book = get_book_text(sys.argv[1])
num_words = number_of_words(entire_book)
num_characters = number_of_characters(entire_book)
print("============ BOOKBOT ============")
print(f"Analyzing book found at {sys.argv[1]}...")
print("----------- Word Count ----------")
print(f"Found {num_words} total words")
print("----------- Character Count ----------")
sorted_characters = sorting(num_characters)
for sorted_character in sorted_characters:
print(f"{sorted_character["char"]}: {sorted_character["num"]}")
print("============= END ===============")
main()