-
Notifications
You must be signed in to change notification settings - Fork 0
/
library_front(updated).py
186 lines (172 loc) · 9.04 KB
/
library_front(updated).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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import streamlit as st
import mysql.connector
import pandas as pd
import datetime
st.set_page_config(page_title="YOURLIBRARY",page_icon="https://e0.pxfuel.com/wallpapers/540/340/desktop-wallpaper-lot-of-books-in-library.jpg")
choice=st.sidebar.selectbox("Menu",("Home","Student Login","Admin Login"))
st.sidebar.image("https://photosfile.com/wp-content/uploads/2023/01/Study-DP-2.jpg")
st.sidebar.image("https://cdn.pixabay.com/photo/2016/02/16/21/07/books-1204029_640.jpg")
if choice=="Home":
st.title("Library Management System")
st.text(" HEY! WELCOME TO YOURLIBRARY 📚👩🎓👨🎓🤓")
st.image('https://images.unsplash.com/photo-1481627834876-b7833e8f5570?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8bGlicmFyeXxlbnwwfHwwfHx8MA%3D%3D&w=1000&q=80')
st.text("A reader lives a thousand lives before he dies.....")
st.text("The man who never reads lives only one")
elif choice=="Student Login":
st.image("https://img.freepik.com/premium-vector/college-university-library-study-place-students-professors-borrowing-reserving-books-online-access-scientific-publications-cartoon-vector-illustration_1284-71255.jpg")
st.text("Hi there 😊 Please enter your UserID and Password.")
if 'login' not in st.session_state:
st.session_state['login']=False
if(not st.session_state['login']):
U=st.text_input("enter UserID:")
P=st.text_input("enter Password:")
btn=st.button("Login")
if btn:
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select * from Users")
for row in c:
if(row[0]==U and row[1]==P):
st.session_state['login']=True
st.experimental_rerun()
break
if(not st.session_state['login']):
st.header("SORRY 😢. Incorrect ID or Password. Please try again later")
if(st.session_state['login']):
st.header("You logged in successfully 😁👍")
ch1=st.selectbox("Choose",("🏠","Search🔍","View books📚","Issue books 📖📖"))
if(ch1=="🏠"):
st.image("https://cdn.pixabay.com/photo/2015/11/19/21/10/glasses-1052010_640.jpg")
elif(ch1=='Search🔍'):
st.image('https://www.venminder.com/hubfs/Blog_Images/2022_Blog_Posts/04.12.2022-record-retention-how-long-do-you-keep-vendor-documents-FEATURED.jpg')
j=st.checkbox('By Genre',)
if j:
a=mysql.connector.connect(host='localhost',user='root',password='abcde123',database='LMS')
c=a.cursor()
c.execute('select distinct genre from books order by genre')
l=[]
for i in c:
l.append(i)
df=pd.DataFrame(data=l,columns=c.column_names)
st.table(df)
i=st.text_input("Enter the genre")
a=mysql.connector.connect(host='localhost',user='root',password='abcde123',database='LMS')
c=a.cursor()
c.execute('select * from books where genre=%s',(i,))
l=[]
for i in c:
l.append(i)
df=pd.DataFrame(data=l,columns=c.column_names)
st.dataframe(df)
elif(ch1=="View books📚"):
cv=st.selectbox('Select',('View all','View all Authors','View all Genres'))
if(cv=='View all'):
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select * from Books")
b=[]
for i in c:
b.append(i)
df=pd.DataFrame(data=b,columns=c.column_names)
st.dataframe(df)
elif(cv=='View all Authors'):
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select distinct author from books")
b=[]
for i in c:
b.append(i)
df=pd.DataFrame(data=b,columns=c.column_names)
st.dataframe(df)
else:
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select distinct genre from books")
b=[]
for i in c:
b.append(i)
df=pd.DataFrame(data=b,columns=c.column_names)
st.dataframe(df)
elif(ch1=="Issue books 📖📖"):
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select * from Books")
b=[]
for i in c:
b.append(i)
df=pd.DataFrame(data=b,columns=c.column_names)
st.dataframe(df)
B=st.text_input("Enter the book id")
d=st.text_input("Enter your ID")
btt=st.button("Issue")
if btt:
dt=str(datetime.datetime.now())
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("insert into Issue_book values(%s,%s,%s)",(dt,B,d))
mydb.commit()
st.header("Book issued successfully😁👍")
elif choice=="Admin Login":
st.image("https://img.freepik.com/premium-vector/librarian-concept-library-staff-cataloguing-sorting-books-knowledge-education-idea-llibrary-bookshelves-guid-isolated-vector-illustration_613284-1665.jpg")
st.text("Hello Admin 😎 Please enter your UserID and Password")
if 'login' not in st.session_state:
st.session_state['login']=False
if(not st.session_state['login']):
U=st.text_input("enter AdminID:")
P=st.text_input("enter Password:")
btn=st.button("Login")
if btn:
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select * from admin_info")
for row in c:
if(row[0]==U and row[1]==P):
st.session_state['login']=True
st.experimental_rerun()
break
if(not st.session_state['login']):
st.header("SORRY 😢. Incorrect ID or Password. Please try again later")
if(st.session_state['login']):
st.header("You logged in successfully 😁👍")
ch2=st.selectbox("Select",("📚","View Books","Add Books","Remove Books",'View issued books'))
if(ch2=="📚"):
st.image("https://cdn.gtricks.com/2019/09/5-book-reading-android-apps-to-read-and-manage-books-for-free-1280x720.jpg")
elif(ch2=="View Books"):
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select * from Books")
b=[]
for i in c:
b.append(i)
df=pd.DataFrame(data=b,columns=c.column_names)
st.dataframe(df)
elif(ch2=="Add Books"):
x=st.text_input("Enter the Book_ID")
y=st.text_input("Enter the book name")
z=st.text_input("Enter the author name")
k=st.text_input("Enter the genre")
bti=st.button("Add")
if bti:
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("insert into Books values(%s,%s,%s,%s)",(x,y,z,k))
mydb.commit()
st.header("Book added successfully😁👍")
elif(ch2=="Remove Books"):
x=st.text_input("Enter the Book_ID")
bti=st.button("Remove")
if bti:
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("delete from books where BookID=%s",(x,))
mydb.commit()
st.header("Book removed successfully😁👍")
else:
mydb=mysql.connector.connect(host="localhost",user="root",password="abcde123",database="LMS")
c=mydb.cursor()
c.execute("select * from issue_book")
b=[]
for i in c:
b.append(i)
df=pd.DataFrame(data=b,columns=c.column_names)
st.dataframe(df)