-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (29 loc) · 963 Bytes
/
Copy pathmain.py
File metadata and controls
39 lines (29 loc) · 963 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, report
def get_book_text(flie_path):
file_contents = ""
with open(flie_path) as f:
file_contents = f.read()
return file_contents
def print_report(character_list, word_count):
print("============ BOOKBOT ============")
print("Analyzing book found at books/frankenstein.txt...")
print("----------- Word Count ----------")
print(f"Found {word_count} total words")
print("--------- Character Count -------")
for item in character_list:
if not item["char"].isalpha():
continue
print(f"{item["char"]}: {item["num"]}")
print("============= END ===============")
def main():
if len(sys.argv) != 2:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
path = sys.argv[1]
book = get_book_text(path)
num_words = count_words(book)
num_characters = count_characters(book)
dict = report(num_characters)
print_report(dict, num_words)
main()