Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions database/books.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title,author,isbn,AvailableInLibrary,timestamp
IKIGAI,Hector Garcia,978-1-786330-89-5,Yes,2025-06-30 20:01:55
2 changes: 2 additions & 0 deletions database/users.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name,UserID,BookInHand,timestamp
Hema,123,,2025-06-30 18:24:15
62 changes: 42 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -31,35 +41,47 @@ 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")
print("4. 📜 List Users")
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:
"""
Expand Down