Question
PYTHON Need list members and exit Tasks to be performed : 1) Add Books 2) Remove Books 3) Add members 4) Remove members 5) Allocate
PYTHON
Need list members and exit
Tasks to be performed :
1) Add Books 2) Remove Books 3) Add members 4) Remove members 5) Allocate Books to members 6) DeAllocate Books to members
DB/Flat-File Details : BOOKS --> Title, Author, Publication, Year, ISBN, No of same books
MEMBER --> User_Id, Name, Phone_No
Issues --> issue_id, User_Id, ISBN, Start_Date, End_Date
functions to be perforemed:
add books : Insert details of the books using a simple form that takes in all the data. If same ISBN, then +1 to no of same books column
remove books : Remove Books option --> Enter ISBN --> Remove --> Confirmation. (If multiple books with same ISBN, then : Remove one book or Remove All option )
add Members: Insert details of the members using a simple form that takes in all the data.
remove Members : Members --> Remove Members --> Enter User_Id --> Confirmation --> Remove
Issueing :
Allocation : Issueing --> Allocate --> Enter ISBN No, User_id, start_date, end_date. Generates issue_id on "Allocate" click --> -1 to no of same books
DeAllocation : Issueing --> DeAllocate --> Enter issue_id/user_id :
if issue_id --> check isbn no --> deaalocate --> confirm --> +1 to no of same books
if user_id --> check issue history --> deallocate last entry --> confirm --> +1 to no of same books Code is:
import peewee
from peewee import *
db = peewee.SqliteDatabase('library.db')
class book(Model): #Table for Books
title = CharField()
author = CharField()
publication = CharField()
pub_year = IntegerField()
isbn = CharField()
num_of_books = IntegerField()
class Meta:
database = db
class member(Model): #Table for members
user_id = CharField()
name = CharField()
phone_no = CharField()
class Meta:
database = db
class issue_history(Model): #Table for issue handling
user_id = ForeignKeyField(member, related_name='pets')
isbn = ForeignKeyField(book, related_name='library')
issue_id = CharField()
issue_date = DateField()
return_date = DateField()
current_status = TextField()
class Meta:
database = db
def initialize_db(): #function to connect to db
db.connect()
try:
db.create_tables([book, member, issue_history])
except OperationalError:
# Table already exists. Do nothing
pass
def deinit(): #func to close connection to db
db.close()
def add_book(): #func to enter a new book
book_title = raw_input('Enter the book title: ')
book_author = raw_input('Enter the book author: ')
book_publication = raw_input('Enter the book publication: ')
book_pub_year = raw_input('Enter the year of publication of book: ')
book_isbn = raw_input('Enter the ISBN code of book: ')
#book_no = number of books having same ISBN
def add_book_to_db(comment, TableName=book): #func to actually save books to db
book_data = book(title=book_title,
author=book_author,
publication=book_publication,
pub_year=book_pub_year,
isbn=book_isbn,
current_status=current_status)
book_data.save()
def add_member(): #func to add a new member
user_id = raw_input('Enter the user_id: ')
member_name = raw_input('Enter the member name: ')
member_phone_no = raw_input('Enter the phone number of the member: ')
def add_member_to_db(comment, TableName=member): #func to actually save a new member to db
member_data = book(user_id=user_id,
name=member_name,
phone_no=member_phone_no)
book_data.save()
def allocate(): #func to allocate a book
alloc_book_isbn = raw_input('Enter book isbn to be allocated: ')
#check alloc_book_id with actual book id in database
if alloc_book_id in book_isbn:
alloc_member_id = raw_input('Enter member id receving the book:')
#checks if correct user_id is entered
if alloc_member_id in user_id:
issue_date = raw_input('Enter issueing date:')
return_date = raw_input('Enter return date:')
#checks if date is properly entered or not
if start_date > return_date:
print ('Issueing date cannot be after return date')
#go to line 37
else :
issue_id = issue_date + user_id + return_date
issue_data.save()
issue.append(sr_no)
current_status = 'issued'
print 'This is your issue id: {0}'.format(issue_id)
print 'Your return date is: {0}'.format(return_date)
else:
print ('user_id entered does not exist')
#go to line line 35
else:
print ('ISBN entered is not present in the database')
#go to line 32
def save_allocate_to_db(comment, TableName=issue_history): #func to save the new allocation data to db
issue_data = book(user_id=alloc_member_id,
isbn=alloc_book_isbn,
issue_id=issue_id,
issue_date=issue_date,
return_date=return_date,
num_of_books=book_no)
issue_data.save()
def de_allocate(): #func to de-allocate a book
de_alloc_issue_id = raw_input('Enter the issue id provided to you:')
#check alloc_book_id with actual book id in database
if de_alloc_issue_id in issue_data:
if today_date == return_date in issue_data:
print ('Book received')
book_no += 1
current_status = 'returned'
elif today_date
overdue_days = return_date - today_date
fine = 5*overdue_days
print "Your fine is Rs", fine
current_status = 'returned'
else:
book_no+= 1
print 'Thank you for choosing Python Library'
#def update_de_allocate_to_db():
#function to add returned status to book
def remove_book():
check_isbn = raw_input('Enter the ISBN code of the book you want to remove: ')
for check_isbn in book_isbn(1,10):
#remove book action
book = book.get(book_isbn == check_isbn)
book.delete_instance()
print 'The book',check_isbn,'has been deleted.'
def remove_member(): #func to remove member from db
rem_member_id = raw_input("Enter member's user_id : ")
# remove member action
member = member.get(user_id == rem_member_id)
member.delete_instance()
print 'Member',rem_member_id,'has been removed.'
print """
Welcome to Python Library System.
a To add a book
b To add a member
c To allocate a book
d To return a book
e To remove a book from the collection
f To remove a member from the book
"""
user_option = raw_input('Enter your choice now:')
user_option = user_option.lower()
if user_option == 'a':
add_book()
elif user_option == 'b':
add_member()
elif user_option == 'c':
allocate()
elif user_option == 'd':
de_allocate()
elif user_option == 'e':
remove_book()
elif user_option == 'f':
remove_member()
else:
print "Invalid choice"
initialize_db()
3. Your task is to create a library manager as a menu-driven console application. The system should have the following functionalities in their menu: i. Add books ii. Remove books iii. Add membership iv. Remove membership Rent book vi. List books List members viii. Exit V. vii. You need to create separate files to store information of books, members, book rentals. When the system starts, it should import all contents of the file into the system, if the files are not empty. All-important fields should be checked for empty or incorrect format. Examples: name, DOB, etc. should not be blank. Phone numbers should be a standard format, etc. Also, you may add any other related functionality as wellStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started