diff --git a/database/books.csv b/database/books.csv new file mode 100644 index 0000000..81110e4 --- /dev/null +++ b/database/books.csv @@ -0,0 +1,2 @@ +title,author,isbn,AvailableInLibrary,timestamp +IKIGAI,Hector Garcia,978-1-786330-89-5,Yes,2025-06-30 20:01:55 diff --git a/database/users.csv b/database/users.csv new file mode 100644 index 0000000..78199bf --- /dev/null +++ b/database/users.csv @@ -0,0 +1,2 @@ +Name,UserID,BookInHand,timestamp +Hema,123,,2025-06-30 18:24:15 diff --git a/main.py b/main.py index cb9fe7a..e128806 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,16 @@ from user_management import UserManagement from checkout_management import CheckoutManagement from libutils.storage import Storage +import re + +def format_isbn(isbn): + # Remove non-digit characters + digits = re.sub(r'\D', '', isbn) + if len(digits) != 13: + return None + return f"{digits[0:3]}-{digits[3]}-{digits[4:10]}-{digits[10:12]}-{digits[12]}" + + class LibraryManagementSystem: def __init__(self): @@ -31,7 +41,7 @@ def display_main_menu(self) -> str: Returns: str: The user's choice. """ - print(f"\n-------------------------------\nšŸ›ļø Library Management System šŸ›ļø\n-------------------------------") + print("\n-------------------------------\nšŸ›ļø Library Management System šŸ›ļø\n-------------------------------") print("1. šŸ†• Add Book") print("2. šŸ“š List Books") print("3. šŸ†• Add User") @@ -39,27 +49,39 @@ def display_main_menu(self) -> str: print("5. āœ… Checkout Book") print("6. ā›” Exit") return input("Enter choice: ") + + + + + def add_book(self, title: str, author: str, isbn: str) -> None: - """ - Adds a book to the library. - - Args: - title (str): The title of the book. - author (str): The author of the book. - isbn (str): The ISBN of the book. - """ - try: - self.book_manager.add_book(title, author, isbn) - except ValueError as e: - if str(e).strip() == "Invalid ISBN": - print(f"\nāŒ Error: {e} āŒ") - print("Valid ISBN example: 978-0-123456-78-9") - elif str(e).strip() == "Book with the same ISBN already exists.": - print(f"\nāŒ Error: {e} āŒ") - print(self.list_books()) - else: - print(f"\nāŒ Error: {e} āŒ") + """ + Adds a book to the library. + + Args: + title (str): The title of the book. + author (str): The author of the book. + isbn (str): The ISBN of the book. + """ + formatted_isbn = format_isbn(isbn) + if not formatted_isbn: + print("\nāŒ Error: Invalid ISBN āŒ") + print("Valid ISBN example: 978-0-123456-78-9") + return + + try: + self.book_manager.add_book(title, author, formatted_isbn) + except ValueError as e: + if str(e).strip() == "Invalid ISBN": + print(f"\nāŒ Error: {e} āŒ") + print("Valid ISBN example: 978-0-123456-78-9") + elif str(e).strip() == "Book with the same ISBN already exists.": + print(f"\nāŒ Error: {e} āŒ") + print(self.list_books()) + else: + print(f"\nāŒ Error: {e} āŒ") + def checkout_book(self) -> None: """