Library Management System
import os
from datetime import datetime
from rapidfuzz.fuzz import partial_ratio
def search(text, books, threshold=80):
matches = [
book for book in books
if partial_ratio(text.lower(), book.lower()) >= threshold
]
return len(matches) > 0, matches
books = [
"The 7 Habits of Highly Effective People - Stephen R. Covey",
"How to Win Friends and Influence People - Dale Carnegie",
"Atomic Habits - James Clear",
"Think and Grow Rich - Napoleon Hill",
"The Power of Now - Eckhart Tolle",
"Awaken the Giant Within - Tony Robbins",
"The Subtle Art of Not Giving a F*ck - Mark Manson",
"The Four Agreements - Don Miguel Ruiz",
"The Power of Positive Thinking - Norman Vincent Peale",
"You Are a Badass - Jen Sincero",
"Mindset: The New Psychology of Success - Carol S. Dweck",
"The Gifts of Imperfection - Brené Brown",
"Man's Search for Meaning - Viktor E. Frankl",
"Daring Greatly - Brené Brown",
"Make Your Bed - Admiral William H. McRaven",
"Deep Work - Cal Newport",
"Can't Hurt Me - David Goggins",
"Who Moved My Cheese? - Spencer Johnson",
"The Magic of Thinking Big - David J. Schwartz",
"Grit: The Power of Passion and Perseverance - Angela Duckworth",
"Drive: The Surprising Truth About What Motivates Us - Daniel H. Pink",
"Essentialism: The Disciplined Pursuit of Less - Greg McKeown",
"The 5 Second Rule - Mel Robbins",
"Eat That Frog! - Brian Tracy",
"The Compound Effect - Darren Hardy",
"Milestones - Sayyid Qutb",
"In the Shade of the Qur'an - Sayyid Qutb",
"The Islamic Way of Life - Sayyid Abul A'la Maududi",
"Towards Understanding Islam - Sayyid Abul A'la Maududi",
"Fundamentals of Islam - Sayyid Abul A'la Maududi",
"Jihad in Islam - Sayyid Abul A'la Maududi",
"Islamic Concept of Justice - Sayyid Abul A'la Maududi",
"The Message of the Qur'an - Muhammad Asad",
"The Principles of State and Government in Islam - Muhammad Asad",
"The Road to Mecca - Muhammad Asad",
"Islam Between East and West - Alija Izetbegovic",
"The Reconstruction of Religious Thought in Islam - Allama Iqbal",
"The Revival of Religious Sciences - Imam Al-Ghazali",
"Islamic Civilization: Its Foundational Beliefs and Principles - Mustafa Sibai",
"Social Justice in Islam - Sayyid Qutb",
"The Ideal Muslim Society - Muhammad Ali Hashmi",
"Minhaj Al-Muslim (The Way of the Muslim) - Abu Bakr Jabir Al-Jazairy",
"In Pursuit of Justice: The Jurisprudence of Human Rights in Islam - Abdullahi An-Na'im",
"The Rights of Women in Islam - Maulana Wahiduddin Khan",
"The Lawful and the Prohibited in Islam - Yusuf Al-Qaradawi",
"Muslim Civilization: The Causes of Decline and the Need for Reform - M. Umer Chapra",
"The Call to Islam - Hasan Al-Banna",
"The Political Thought of Ibn Taymiyya - Ibn Taymiyya",
"Islamic Law and Constitution - Abul Ala Maududi",
"The Early Caliphate - Muhammad Ali"
]
def save_to_file(data, filename="data.txt"):
"""Save data to a file, appending it to the end."""
with open(filename, "a") as file:
file.write(data + "\n")
# print user details
filename = "data.txt"
print("Enter user details:")
# Take user input
name = input("Name: ")
id_number = int(input("ID Number: "))
# Get the current date and time
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
# Format the details and save
entry = f"Name: {name}, ID: {id_number}, Timestamp: {timestamp}"
save_to_file(entry, filename)
print(f"Entry Date and Time: {timestamp}")
print(f"Data saved successfully to '{filename}'!")
while(True):
print("\nEnter the corresponding number to perform the task\n")
print("1-Borrow a Book \n2-Donate a Book \n3-Check Book Availability ")
do = int(input())
if(do == 1):
print('Which book do you want to borrow?')
want = input()
available, matching_books = search(want,books)
if available:
print(f"'{want}' is available. \nMatching books: ")
for book in matching_books:
print(f"{book}")
print("Do you want to borrow this book? (yes/no)")
choice = input()
if choice.lower() == "yes":
print("Thank you for borrowing the book!")
else:
print("No problem, you can borrow another book.")
else:
print(f"'{want}' is not available.")
elif(do == 2):
print('Which book do you want to donate?')
donate = input()
print("Enter the author name: ")
author = input()
print(f"Thank you for donating {donate} by {author}.")
elif(do == 3):
print("Enter the book name you want to check availability: ")
check = input()
available, matching_books = search(check,books)
if available:
print("The book is available.")
else:
print("The book is not available.")
print("Do you want to continue? (yes/no)")
again = input()
if again.lower() == "no":
break
Comments
Post a Comment