-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
169 lines (109 loc) · 4.84 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from modules.book_management import list_books,add_book,update_book,delete_book,save_books
from database.db_setup import initialize_database
from modules.user_management import add_user_or_admin, list_users,verify_user
from modules.checkout_management import CheckoutManagement
from datetime import datetime, timedelta
from storage import Storage
from loguru import logger
import sys
from utils.utils import add_checkouts_new,update_new_checkout,add_book_new,update_new_book
# Configure logging
logger.add(sys.stdout, level="INFO") # Log to the console
store=Storage()
checkout_manager= CheckoutManagement()
def main_menu_admin():
"""Display the main menu and return the user's choice."""
print("1. List Books")
print("2. Add Book")
print("3. Update Book")
print("4. Delete Book")
print("5. Add user or admin")
print("6. List Checkouts")
print("7. Add Checkout")
print("8. Update Checkout")
print("9. Delete Checkout")
print("10. List Users")
return input("Enter your choice: ")
def main_menu_user():
print("1.List Books")
print("2.Reserve Books")
return input("Enter your choice: ")
def main():
# Create an instance of BookManagement
try:
logger.info("Initializing database...")
connection = initialize_database()
if connection:
logger.info("Database initialized successfully.")
else:
logger.error("Database initialization failed.")
return
role = input("Enter the role of the user (admin/user): ").strip()
id = int(input("Enter the id of the user: "))
password = input("Enter the password of the user: ").strip()
logger.info(f"User {id} trying to log in as {role}.")
verified_role = verify_user(role, id, password)
if verified_role == 'admin':
logger.info("Admin verified")
# else:
# logger.error("Invalid credentials.")
# print("Invalid credentials. Access denied.")
# except Exception as e:
# logger.exception(f"An error occurred: {e}")
print('\n\n\n')
print("Admin verified")
print('\n\n\n')
print("<------------------------------------------------------------>")
print('\n\n\n\n')
print("Welcome to the Library Management System")
choice= main_menu_admin()
if choice == '1':
filename = input("Type Books.csv to know the books in the library: ")
list_books(filename)
elif choice == '2':
add_book_new()
elif choice == '3':
update_new_book()
elif choice == '4':
book_id = int(input("Enter book ID to delete: "))
filename= input("Type Books.csv to delete from the file ")
delete_book(book_id,filename)
elif choice == '5':
id = int(input("Enter the ID: "))
name = input("Enter the name ")
password = input("Enter the password ")
role = input("Enter the role")
add_user_or_admin(id,name,password,role)
elif choice == '6':
filename = input("Type Checkout.csv to load checkouts from the file: ")
checkout_manager.list_checkouts(filename)
elif choice == '7':
add_checkouts_new()
elif choice == '8':
update_new_checkout(id)
elif choice=='9':
book_id = int(input("Enter book ID to delete: "))
filename= input("Type Checkout.csv to delete from the file ")
checkout_manager.delete_checkouts(book_id,filename)
elif choice == '10':
list_users()
else:
print("Invalid choice. Please try again.")
elif verified_role == 'user':
logger.info(f"User {id} verified")
print("Hi Student:"+" "+str(id))
print('\n\n\n')
print("<------------------------------------------------------------>")
print('\n\n\n\n')
print("Welcome to the Library Management System")
choice=main_menu_user()
if choice=='1':
filename = input("Type Books.csv to know the books in the library: ")
list_books(filename)
if choice=='2':
# Call the function to handle the checkout
add_checkouts_new(id)
except Exception as e:
logger.exception(f"An error occurred: {e}")
if __name__ == "__main__":
main()