feat: complete project
This commit is contained in:
@@ -1,8 +1,47 @@
|
||||
"""Main entrypoint for bookbot"""
|
||||
"""Entrypoint for bookbot"""
|
||||
|
||||
import sys
|
||||
|
||||
from stats import count_characters_in_book, count_words_in_book, sort_character_counts
|
||||
|
||||
|
||||
def get_book_text(file_path: str) -> str:
|
||||
"""Retrieves the contents of the given file"""
|
||||
|
||||
with open(file_path, mode="r", encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def main():
|
||||
"""Main method for bookbot"""
|
||||
print("Hello from bookbot!")
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python3 main.py <path_to_book>")
|
||||
sys.exit(1)
|
||||
|
||||
book_path = sys.argv[1]
|
||||
book_text = get_book_text(book_path)
|
||||
word_count = count_words_in_book(book_text)
|
||||
character_counts = count_characters_in_book(book_text)
|
||||
sorted_counts = sort_character_counts(character_counts)
|
||||
|
||||
print("============ BOOKBOT ============")
|
||||
print(f"Analyzing book found at {book_path}...")
|
||||
print("----------- Word Count ----------")
|
||||
print(f"Found {word_count} total words")
|
||||
print("--------- Character Count -------")
|
||||
|
||||
for item in sorted_counts:
|
||||
char = item["char"]
|
||||
|
||||
if not char.isalpha():
|
||||
continue
|
||||
|
||||
print(f"{char}: {item["num"]}")
|
||||
|
||||
print("============= END ===============")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user