├── Library Management using Python ├── README.md └── main.py /Library Management using Python: -------------------------------------------------------------------------------- 1 | Library Management using Python 2 | 3 | Forms using HTML, Flat-file : json 4 | 5 | 6 | Tasks to be performed : 7 | 8 | 1) Add Books 9 | 2) Remove Books 10 | 3) Add members 11 | 4) Remove members 12 | 5) Allocate Books to members 13 | 6) DeAllocate Books to members 14 | 15 | 16 | DB/Flat-File Details : 17 | 18 | BOOKS --> Title, Author, Publication, Year, ISBN, No of same books 19 | 20 | MEMBER --> User_Id, Name, Phone_No 21 | 22 | Issues --> issue_id, User_Id, ISBN, Start_Date, End_Date 23 | 24 | 25 | Functions : 26 | 27 | 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 28 | 29 | Remove books : Remove Books option --> Enter ISBN --> Remove --> Confirmation. 30 | (If multiple books with same ISBN, then : Remove one book or Remove All option ) 31 | 32 | Add Members: Insert details of the members using a simple form that takes in all the data. 33 | 34 | Remove Members : Members --> Remove Members --> Enter User_Id --> Confirmation --> Remove 35 | 36 | Issueing : 37 | 38 | Allocation : Issueing --> Allocate --> Enter ISBN No, User_id, start_date, end_date. Generates issue_id on "Allocate" click --> -1 to no of same books 39 | 40 | DeAllocation : Issueing --> DeAllocate --> Enter issue_id/user_id : 41 | 42 | if issue_id --> check isbn no --> deaalocate --> confirm --> +1 to no of same books 43 | 44 | if user_id --> check issue history --> deallocate last entry --> confirm --> +1 to no of same books -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Library-management 2 | Library Management system with basic functionality built using python 3 | A part of the mentoring project in the Devs and hackers group. 4 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import peewee 2 | from peewee import * 3 | 4 | db = peewee.SqliteDatabase('library.db') 5 | 6 | class book(Model): #Table for Books 7 | title = CharField() 8 | author = CharField() 9 | publication = CharField() 10 | pub_year = IntegerField() 11 | isbn = CharField() 12 | num_of_books = IntegerField() 13 | 14 | class Meta: 15 | database = db 16 | 17 | 18 | class member(Model): #Table for members 19 | user_id = CharField() 20 | name = CharField() 21 | phone_no = CharField() 22 | 23 | class Meta: 24 | database = db 25 | 26 | class issue_history(Model): #Table for issue handling 27 | user_id = ForeignKeyField(member, related_name='pets') 28 | isbn = ForeignKeyField(book, related_name='library') 29 | issue_id = CharField() 30 | issue_date = DateField() 31 | return_date = DateField() 32 | current_status = TextField() 33 | 34 | class Meta: 35 | database = db 36 | 37 | 38 | def initialize_db(): #function to connect to db 39 | db.connect() 40 | try: 41 | db.create_tables([book, member, issue_history]) 42 | except OperationalError: 43 | # Table already exists. Do nothing 44 | pass 45 | 46 | def deinit(): #func to close connection to db 47 | db.close() 48 | 49 | 50 | def add_book(): #func to enter a new book 51 | book_title = raw_input('Enter the book title: ') 52 | book_author = raw_input('Enter the book author: ') 53 | book_publication = raw_input('Enter the book publication: ') 54 | book_pub_year = raw_input('Enter the year of publication of book: ') 55 | book_isbn = raw_input('Enter the ISBN code of book: ') 56 | #book_no = number of books having same ISBN 57 | 58 | 59 | def add_book_to_db(comment, TableName=book): #func to actually save books to db 60 | book_data = book(title=book_title, 61 | author=book_author, 62 | publication=book_publication, 63 | pub_year=book_pub_year, 64 | isbn=book_isbn, 65 | current_status=current_status) 66 | book_data.save() 67 | 68 | 69 | def add_member(): #func to add a new member 70 | user_id = raw_input('Enter the user_id: ') 71 | member_name = raw_input('Enter the member name: ') 72 | member_phone_no = raw_input('Enter the phone number of the member: ') 73 | 74 | 75 | def add_member_to_db(comment, TableName=member): #func to actually save a new member to db 76 | member_data = book(user_id=user_id, 77 | name=member_name, 78 | phone_no=member_phone_no) 79 | book_data.save() 80 | 81 | 82 | def allocate(): #func to allocate a book 83 | alloc_book_isbn = raw_input('Enter book isbn to be allocated: ') 84 | #check alloc_book_id with actual book id in database 85 | if alloc_book_id in book_isbn: 86 | alloc_member_id = raw_input('Enter member id receving the book:') 87 | #checks if correct user_id is entered 88 | if alloc_member_id in user_id: 89 | issue_date = raw_input('Enter issueing date:') 90 | return_date = raw_input('Enter return date:') 91 | #checks if date is properly entered or not 92 | if start_date > return_date: 93 | print ('Issueing date cannot be after return date') 94 | #go to line 37 95 | 96 | else : 97 | issue_id = issue_date + user_id + return_date 98 | issue_data.save() 99 | issue.append(sr_no) 100 | current_status = 'issued' 101 | print 'This is your issue id: {0}'.format(issue_id) 102 | print 'Your return date is: {0}'.format(return_date) 103 | 104 | else: 105 | print ('user_id entered does not exist') 106 | #go to line line 35 107 | 108 | else: 109 | print ('ISBN entered is not present in the database') 110 | #go to line 32 111 | 112 | 113 | def save_allocate_to_db(comment, TableName=issue_history): #func to save the new allocation data to db 114 | issue_data = book(user_id=alloc_member_id, 115 | isbn=alloc_book_isbn, 116 | issue_id=issue_id, 117 | issue_date=issue_date, 118 | return_date=return_date, 119 | num_of_books=book_no) 120 | issue_data.save() 121 | 122 | 123 | def de_allocate(): #func to de-allocate a book 124 | de_alloc_issue_id = raw_input('Enter the issue id provided to you:') 125 | #check alloc_book_id with actual book id in database 126 | if de_alloc_issue_id in issue_data: 127 | if today_date == return_date in issue_data: 128 | print ('Book received') 129 | book_no += 1 130 | current_status = 'returned' 131 | 132 | elif today_date < return_date: 133 | overdue_days = return_date - today_date 134 | fine = 5*overdue_days 135 | print "Your fine is Rs", fine 136 | current_status = 'returned' 137 | 138 | else: 139 | book_no+= 1 140 | print 'Thank you for choosing Python Library' 141 | 142 | #def update_de_allocate_to_db(): 143 | #function to add returned status to book 144 | 145 | 146 | def remove_book(): 147 | check_isbn = raw_input('Enter the ISBN code of the book you want to remove: ') 148 | 149 | for check_isbn in book_isbn(1,10): 150 | #remove book action 151 | book = book.get(book_isbn == check_isbn) 152 | book.delete_instance() 153 | 154 | print 'The book',check_isbn,'has been deleted.' 155 | 156 | 157 | 158 | 159 | def remove_member(): #func to remove member from db 160 | rem_member_id = raw_input("Enter member's user_id : ") 161 | # remove member action 162 | member = member.get(user_id == rem_member_id) 163 | member.delete_instance() 164 | 165 | print 'Member',rem_member_id,'has been removed.' 166 | 167 | 168 | 169 | 170 | print """ 171 | Welcome to Python Library System. 172 | a To add a book 173 | b To add a member 174 | c To allocate a book 175 | d To return a book 176 | e To remove a book from the collection 177 | f To remove a member from the book 178 | """ 179 | 180 | user_option = raw_input('Enter your choice now:') 181 | user_option = user_option.lower() 182 | 183 | 184 | 185 | 186 | 187 | if user_option == 'a': 188 | add_book() 189 | 190 | elif user_option == 'b': 191 | add_member() 192 | 193 | elif user_option == 'c': 194 | allocate() 195 | 196 | elif user_option == 'd': 197 | de_allocate() 198 | 199 | elif user_option == 'e': 200 | remove_book() 201 | 202 | elif user_option == 'f': 203 | remove_member() 204 | else: 205 | print "Invalid choice" 206 | 207 | if __name__ == '__main__': 208 | initialize_db() 209 | 210 | 211 | --------------------------------------------------------------------------------