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
7 changes: 7 additions & 0 deletions Library_system/Book.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-------------------------------------------------------------------
- BOOKS = 1
- ADD BOOK = 2
- SEARCH BOOK = 3
- DELETE BOOK = 4 EXIT = 0
-
------------------------------------------------------------------
7 changes: 7 additions & 0 deletions Library_system/Membership.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---------------------------------------------------------------------
- All MEMBERS = 1 = LEND BOOK = 5 -
- ADD MEMBER = 2 = RETURN BOOK = 6 -
- UPDATE MEMBER = 3 = TRACK BOOK = 7 -
- DELETE MEMBER = 4 = EXIT = 0 -
- -
---------------------------------------------------------------------
8 changes: 8 additions & 0 deletions Library_system/Welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--------------------------------------------------------------------------------------------
- Welcome to public Library -
- -
- 1-Membership Transactions 1 -
- 2-Book Transactions 2 -
- 3-Exit 0 -
- -
--------------------------------------------------------------------------------------------
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Library_system/__pycache__/screening.cpython-312.pyc
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions Library_system/book.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
92 changes: 92 additions & 0 deletions Library_system/lending.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import json
import os
import time_management
import new_book_transaction
import membership

def write_tracking(data):

try:
with open('Library_system/tracking.json', 'w',encoding="utf-8") as file:
json.dump(data, file,ensure_ascii=False ,indent=4)
except Exception as e:
print(f"An error occurred while saving: {e}")
return []



def tracking_read():

try:
if not os.path.exists("Library_system/tracking.json") or os.path.getsize("Library_system/tracking.json") == 0:
return []
with open("Library_system/tracking.json", "r", encoding="utf-8", errors="ignore") as file:
tracking_data = json.load(file)
return tracking_data
except FileNotFoundError:
tracking_data = []
return tracking_data


def lending_book(phone_number,barcode):

now_time,return_time = time_management.generate_return_date()

searchBook = new_book_transaction.search_book(barcode)
member_ = membership.members_search(phone_number,inter=1)
print(member_)
print(searchBook)
if member_ and searchBook:
new_track = searchBook|member_
new_track["lend_date"] = now_time
new_track["return_date"] = return_time
tracking_data=tracking_read()

new_book_transaction.delete_book(barcode)
tracking_data.append(new_track)

write_tracking(tracking_data)
else:

print("Member or book not found")



def return_book(barcode): #

tracked_books = tracking_read()

books = new_book_transaction.read()

for tracked_book in tracked_books:

if tracked_book["Barcode"]==barcode:
new_book = {
"Barcode": tracked_book["Barcode"],
"Book_Title": tracked_book["Book_Title"],
"Author": tracked_book["Author"],
"Publisher": tracked_book["Publisher"],
}

books.append(new_book)
new_book_transaction.save(books)

tracked_books = [book for book in tracked_books if book["Barcode"] != tracked_book["Barcode"]]


write_tracking(tracked_books)


def view_lent_books():

tracking_data = tracking_read()
if tracking_data!=[]:
sorted_data = sorted(tracking_data, key=lambda x: x['return_date'])


for track in sorted_data:
print(f" Member ID: {track['member_ID']}\n Member Name: {track['member_name']}\n Member Phone: {track['phone_number']}\n Member Address: {track['address']}\n\n Book Title: {track['Book_Title']}\n Author: {track['Author']}\n Publisher: {track['Publisher']}\n Barcode: {track['Barcode']}\n Lend Date: {track['lend_date']}\n Return Date: {track['return_date']}\n {"="*20}")
else:

print("There is book lended")

131 changes: 131 additions & 0 deletions Library_system/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import new_book_transaction
import membership
from screening import screen
import os
import lending



def get_input(prompt, error_message="Field cannot be empty. Please try again."):
while True:
value = input(prompt).strip().lower()
if value:
return value
print(error_message)


def main_menu():


while True:
try:
screen("Welcome")
option=input("\nPlease choose the options above and press Enter to continue:")

if option == "1":



while True:
screen("Membership")
mem_opt=input("\nPlease choose the options above and press Enter to continue:")

match mem_opt:
case "2":

name = get_input("Enter name and surname: ")
address = get_input("Enter address: ")
phone = get_input("Enter phone number: ")
membership.add_new_member(name, phone, address)

case "4":
if (membership.member_control()):
phone = get_input("Enter phone number of the member to delete: ")
membership.members_delete(phone)
else:
print("No Members")
case "3":
if (membership.member_control()):
phone = get_input("Enter phone number of the member to view details:")
membership.member_update(phone)
else:
print("No Members")




case "1":

membership.member_control()




case "5":

phone_number = get_input("Enter phone number of the member: ")
barcode = get_input("Enter the book barcode to lend: ")
lending.lending_book(phone_number, barcode)
case "6":

barcode = get_input("Enter the book barcode to return: ")
lending.return_book(barcode)
case "7":
lending.view_lent_books()

case "0":
break

case _:
print("Invalid option, please try again")

elif option == "2":
while True:
screen("Book")
book_opt=input("\nPlease choose the options above and press Enter to continue:")
match book_opt:
case "1":

books=new_book_transaction.books()
case "2":
title = get_input("Enter the book title: ")
author = get_input("Enter the author: ")
publisher = get_input("Enter the publisher: ")
res=new_book_transaction.add_book(title, author, publisher)
if res:
print("Book added successfully")
else:
print("Book could not be added.Please try again")

case "4":
barcode = get_input("Enter the book barcode to delete: ")
res=new_book_transaction.delete_book(barcode)

if (res):
print("Book deleted successfully")
else:
print("Book could not be found")
case "3":
title = get_input("Enter the book title to search: ")
res=new_book_transaction.search_book(title)
if (res):
print(f"Title: {res['Book_Title']}\nAuthor: {res['Author']}\nPublisher: {res['Publisher']}\nBarcode: {res['Barcode']}")
else:
print("Book not found")
case "0":
break
case _:
print("Invalid option, please try again")


elif option == "0":
print("Thank you for using the Library System")
break
else:
print("Please input a number between 0 - 2")

except Exception as e:
print(e)

if __name__ == "__main__":
main_menu()
1 change: 1 addition & 0 deletions Library_system/member.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading