Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Optional
from library.model.book import Book
from library.model.genre import Genre


class Library():

# Prints crime audio books
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment pollution: the function's name already describes what is does

def print_longest_crime_audio_book(self) -> str:
crime_audio_books: list[Book] = []
max: Optional[Book] = None

# print banner
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commentary not necessary. Does not say "why"

print("*********************************************")
print("********* Longest Crime Audio Book **********")
print("*********************************************")

for b in self.get_books():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we access _books directly?

if Genre.CRIME in b.genres:
if b._book_type == "Audio":
if max is not None and max.duration < b.duration:
max = b
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is max ever changed from None

# end if
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# end if useless as per python

# end if
else:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed. Same as not having an else

pass
# end else
# end for

print(f"Title: {max.title}")
print(f"Author: {max.authors}")
print(f"Duration: {max.duration}")
print(f"______________________________")
return str(max)

# Constructor
def __init__(self, books: list[Book]):
self._books = books

_books: list[Book] = []
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be placed at the top


def get_books(self) -> list[Book]:
return self._books