Gate Project
Gate Project
PROJECT REPORT
ON
“GATE MANAGEMENT SYSTEM”
SUBMITTED BY
Subesh P
1|Page
Certificate
2|Page
ACKNOWLEDGEMENT
3|Page
INDEX
Introduction.............................................................................5
1. Python..............................................................................5
2. MySQL..............................................................................5
Aim..........................................................................................6
Modules Imported...................................................................6
Functions Used........................................................................6
Source Code............................................................................7
Output...................................................................................17
4|Page
Introduction
1. Python
Python is a popular programming language. It was
created by Guido van Rossum, and released in 1991.
It is used for:
web development (server-side),
software development,
mathematics,
system scripting.
2. MySQL
MySQL is a very popular open-source relational
database management system (RDBMS), released in 1995.
MySQL is ideal for both small and large applications. It is
very fast, reliable, scalable, and easy to use. It is cross-
platform
It is used by:
Huge websites like Facebook, Twitter, Airbnb,
Booking.com, Uber, GitHub, YouTube, etc.
Content Management Systems like WordPress,
Drupal, Joomla, Contao, etc.
A very large number of web developers around the
world
5|Page
Aim
The Project is designed to maintain records of
visitor/resident record who has entered or exited the
industry campus. An industry that has both residential area
and office that must manage entry/exit data of visitor,
employees, residents, etc. This project will fulfil the gate
management of the industry campus. Employee details,
Visitor details, Resident details, Vehicle Details, etc. can be
maintained using this project.
Modules Imported
1. mysql.connector – To integrate Python and MySQL
2. datetime – To fetch Current Date and Time
Functions Used
def – To define a custom Function
connect() – To Connect to MySQL Database from
Python
cursor() – To Execute the given Query/Statement
execute() – To make the Query to be understood by
MySQL i.e. to convert Query to MySQL standard
format
commit() – To save the changes made in the
Database permanently
close() – To Break the connection between Python
and MySQL Database
6|Page
Source Code
# Importing Required Modules
import sqcon as sqcon
import datetime
# Connecting to Database
def database():
mycon = sqcon.connect(
host="localhost",
user="root",
password="Root",
auth_plugin='mysql_native_password'
)
# Creating Databases
mycursor = mycon.cursor()
mycursor.execute("CREATE DATABASE IF NOT EXISTS employee")
mycursor.execute("CREATE DATABASE IF NOT EXISTS vechicle_entry")
mycursor.execute("CREATE DATABASE IF NOT EXISTS visitor_entry")
mycursor.execute("CREATE DATABASE IF NOT EXISTS residental_entry")
# Creating Tables
def emp():
mycon =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql native_password',database='employee')
cur = mycon.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS employee(NAME varchar(30)
not null,EMP_CODE int not null unique,TIME time not null,DEPARTMENT
varchar(30))")
mycon.commit()
7|Page
def veh():
mycon =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password',database='vechicle_entry')
cur = mycon.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS
vechicle_entry(VECHICLE_NUMBER int,DRIVER_NAME varchar(30) not
null,TIME time not null,MATERIAL varchar(30))")
def vis():
mycon =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password',database='visitor_entry')
cur = mycon.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS visitor_entry(NAME varchar(30)
not null,TIME time not null,MOBILE_NUMBER int unique,REASON
varchar(90))")
def res():
mycon =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password',database='residental_entry')
cur = mycon.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS residental_entry(NAME
varchar(30) not null,TIME time not null,HOUSE_NUMBER varchar(10) not
null)")
database()
veh()
emp()
vis()
res()
# Main Program
8|Page
def date_time():
return datetime.datetime.now()
def sql_emp(N,C,T,D):
data =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password', database='employee')
cur = data.cursor()
#if data.is_connected():
#print('connected sucessfully')
q = "INSERT INTO employee(NAME,EMP_CODE,TIME,DEPARTMENT)
VALUES(%s,%s,%s,%s)"
val = (N,C,T,D)
cur.execute(q,val)
data.commit()
data.close()
def sql_update(Sr):
data =
sqcon.connect(host='localhost',user='root',password='Root',database='employ
ee')
cur = data.cursor()
print('WHAT DO YOU WANT TO CHANGE \n PRESS 1 FOR NAME \n PRESS 2
FOR CODE \n PRESS 3 FOR DEAPRTMENT \n PRESS 4 FOR LAST ENTERED DATA
TO CHANGE')
i = int(input('enter number: '))
if i == 1:
n = input('ENTER NAME: ')
cur.execute(f"UPDATE employee SET NAME='{n}' WHERE NAME='{Sr}'")
data.commit()
elif i == 2:
n1 = int(input("enter code: "))
9|Page
cur.execute("UPDATE employee SET EMP_CODE={} WHERE
NAME={}".format(n1,Sr))
data.commit()
elif i == 3:
n2 = input("enter department: ")
cur.execute("UPDATE employee SET DEPARTMENT='{}' WHERE
NAME='{}'".format(n2,Sr))
data.commit()
elif i == 4:
n3 = input("enter name: ")
n4 = int(input("enter emp_code: "))
n5 = input("enter department: ")
cur.execute("UPDATE employee SET
NAME={},EMP_CODE={},DEPARTMENT={} W
10 | P a g e
11 | P a g e
12 | P a g e
13 | P a g e
14 | P a g e
15 | P a g e
16 | P a g e
17 | P a g e
18 | P a g e
19 | P a g e
20 | P a g e
21 | P a g e
22 | P a g e
23 | P a g e
24 | P a g e
25 | P a g e
26 | P a g e
27 | P a g e
28 | P a g e
29 | P a g e
30 | P a g e
31 | P a g e
32 | P a g e
33 | P a g e
34 | P a g e
35 | P a g e
36 | P a g e
37 | P a g e
38 | P a g e
39 | P a g e
40 | P a g e
41 | P a g e
42 | P a g e
43 | P a g e
44 | P a g e
45 | P a g e
46 | P a g e
47 | P a g e
48 | P a g e
49 | P a g e
50 | P a g e
51 | P a g e
52 | P a g e
53 | P a g e
54 | P a g e
55 | P a g e
56 | P a g e
57 | P a g e
58 | P a g e
59 | P a g e
60 | P a g e
61 | P a g e
62 | P a g e
63 | P a g e
64 | P a g e
65 | P a g e
NAME={}".format(n3,n4,n5,Sr))
66 | P a g e
data.commit()
data.close()
def sql_vechicle(VN,DN,T,M):
data =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password', database='vechicle_entry')
cur = data.cursor()
q = "INSERT INTO
vechicle_entry(VECHICLE_NUMBER,DRIVER_NAME,TIME,MATERIAL)
VALUES(%s,%s,%s,%s)"
val = (VN,DN,T,M)
cur.execute(q,val)
data.commit()
data.close()
def sql_vehupdate(veh_Sr):
data =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password', database='vechicle_entry')
cur = data.cursor()
print(
'WHAT DO YOU WANT TO CHANGE \n PRESS 1 FOR VECHICLE NUMBER'
' \n PRESS 2 FOR DRIVER NAME \n PRESS 3 FOR MATERIAL \n PRESS 4 FOR
LAST ENTERED DATA TO CHANGE')
i = int(input('enter number: '))
if i == 1:
n = input('ENTER VECHICLE NUMBER: ')
cur.execute("UPDATE vechicle_entry SET VECHICLE_NUMBER={} WHERE
VECHICLE_NUMBER={}".format(n,veh_Sr))
data.commit()
elif i == 2:
67 | P a g e
n1 = int(input("ENTER DRIVER NAME: "))
cur.execute("UPDATE vechicle_entry SET DRIVER_NAME='{}' WHERE
VECHICLE_NUMBER={}".format(n1,veh_Sr))
data.commit()
elif i == 3:
n2 = input("enter material: ")
cur.execute("UPDATE vechicle_entry SET MATERIAL='{}' WHERE
VECHICLE_NUMBER={}".format(n2,veh_Sr))
data.commit()
elif i == 4:
n3 = input("enter vechicle number: ")
n4 = int(input("enter driver name: "))
n5 = input("enter material: ")
cur.execute("UPDATE vechicle_entry SET
VECHICLE_NUMBER={},DRIVER_NAME='{}',MATERIAL='{}' WHERE
VECHICLE_NUMBER={}".format(n3, n4, n5,veh_Sr))
data.commit()
data.close()
def sql_visitor(N,T,MN,R):
data =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password', database='visitor_entry')
cur = data.cursor()
q = "INSERT INTO visitor_entry(NAME,TIME,MOBILE_NUMBER,REASON)
VALUES(%s,%s,%s,%s)"
val = (N,T,MN,R)
cur.execute(q,val)
data.commit()
data.close()
def sql_residental(N,T,H):
68 | P a g e
data =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password', database='residental_entry')
cur = data.cursor()
q = "INSERT INTO residental_entry(NAME,TIME,HOUSE_NUMBER)
VALUES(%s,%s,%s)"
val = (N,T,H)
cur.execute(q,val)
data.commit()
data.close()
def sql_residentalupdate(res_Sr):
data =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password', database='residental_entry')
cur = data.cursor()
print(
'WHAT DO YOU WANT TO CHANGE \n PRESS 1 FOR NAME'
' \n PRESS 2 FOR HOUSE NUMBER \n PRESS 3 FOR LAST ENTERED DATA TO
CHANGE')
i = int(input("enter number: "))
if i == 1:
n = input('ENTER NAME: ')
cur.execute("UPDATE residental_entry SET NAME='{}' WHERE
NAME='{}'".format(n,res_Sr))
data.commit()
elif i == 2:
n1 = eval(input("ENTER HOUSE NUMBER: "))
cur.execute("UPDATE residental_entry SET HOUSE_NUMBER={} WHERE
NAME='{}'".format(n1, res_Sr))
data.commit()
69 | P a g e
elif i == 3:
n3 = input("enter NAME: ")
n4 = eval(input("enter HOUSE NUMBER: "))
cur.execute(
"UPDATE residental_entry SET NAME={},HOUSE_NUMBER={} WHERE
RESIDENTAL_SERIAL_no={}".format(
n3,n4,res_Sr))
data.commit()
data.close()
def employee():
data =
sqcon.connect(host='localhost',user='root',password='Root',database='employ
ee')
cur = data.cursor()
cur.execute('select * from employee')
dat = cur.fetchall()
for i in dat:
print(i)
print(" IF YOU WANT TO CHANGE ANY DATA ENTER Y/y")
rr = input('enter to change any data')
if rr == 'Y' or rr == 'y':
print('which employee data you want to change')
rr = int(input('enter employee code of the employee: '))
change_emp(rr)
def change_emp(rr):
data =
sqcon.connect(host='localhost',user='root',password='Root',auth_plugin='mys
ql_native_password', database='employee')
cur = data.cursor()
70 | P a g e
n1 = input('enter name of employee:')
n3 = input('enter department:')
n4 = int(input('enter employee code: '))
cur.execute(f'UPDATE employee set NAME = "{n1}",EMP_CODE =
{n4},DEPARTMENT = "{n3}" WHERE EMP_CODE = {rr}')
data.commit()
i = True
while i:
print('want to change more data entry')
print('or want to delete the data')
print('press Y/y to change or D/d to delete the data')
t = input('enter:')
if t == 'Y' or t == 'y':
na = input('enter name:')
change_emp(na)
elif t == 'D' or t == 'd':
n4 = int(input('enter emp code whose data you want to delete: '))
cur.execute(f"delete from employee where EMP_CODE = {n4}")
else:
i = False
def vechicle():
data =
sqcon.connect(host='localhost',user='root',password='Root',database='vechicl
e_entry')
cur = data.cursor()
cur.execute('select * from vechicle_entry')
dat = cur.fetchall()
print('\n')
for i in dat:
71 | P a g e
print(i)
def residental():
data =
sqcon.connect(host='localhost',user='root',password='Root',database='residen
tal_entry')
cur = data.cursor()
cur.execute('select * from residental_entry')
dat = cur.fetchall()
for i in dat:
print(i)
def visitor():
data =
sqcon.connect(host='localhost',user='root',password='Root',database='visitor_
entry')
cur = data.cursor()
cur.execute('select * from visitor_entry')
dat = cur.fetchall()
for i in dat:
print(i)
print("|==============INDUSTRIAL GATE MANGEMENT
SYSTEM==============|")
print('press one "1" or enter Y to enter data in the system:')
print('press one "2" or enter R to retrieve data from the system:')
i = input('enter 1/2 or Y/R:')
# CODE TO ENTER THE DATA INTO THE DATABASE
if (i == '1' or i == 'Y' or i=='y'):
print("ENTER [EMP] OR 1 FOR EMPLOYEE ENTRY")
print("ENTER [VEC] OR 2 FOR VECHICLE ENTRY")
print("ENTER [RES] OR 3 FOR RESIDENTAL ENTRY")
72 | P a g e
print("ENTER [VIS] OR 4 FOR VISITOR ENTRY")
i1 = input('enter your choice press 1,2,3,4=')
if (i1 == '1' or i1 == 'EMP'):
k = True
while k:
n = input('enter name of employee: ')
c = int(input('enter employee code of the employee: '))
t = date_time()
d = input('enter department of the emplyee: ')
sql_emp(n,c,t,d)
print(f"DATA SUCCESSFULLY ENTERED OF EMPLOYEE NUMBER:\n
EMPLOYEE NAME{n}")
print("IF YOU WANT TO CHANGE LAST ENTERED DATA PRESS Y/y else
N/n=")
i2 = input('enter Y/y')
if i2 == 'y' or i2 == 'Y':
sql_update(n)
print('WANT TO ENTER EMPLOYEE DATA AGAIN PRESS Y/y')
K1 = input('enter y/Y else press any key')
if K1 == 'Y' or K1 == 'y':
k = True
else:
k = False
else:
pass
elif (i1 == '2' or i1 == 'VEH'):
vn = int(input('enter vechicle number: '))
dn = input("enter driver name: ")
73 | P a g e
vt = date_time()
ma = input("enter material name: ")
sql_vechicle(vn,dn,vt,ma)
print(f"DATA SICCESSFULLY ENTERED OF VECHICLE SERIAL NUMBER:\n
vechicle number {vn}")
print("IF YOU WANT TO CHANGE LAST ENTERED DATA PRESS Y/y")
i3 = input('enter Y/y: ')
if i3 == 'Y' or i3 == 'y':
sql_vehupdate(vn)
elif (i1 == '3' or i1 == 'RES'):
rn = input("enter name of the person:")
rt = date_time()
hn = input("enter house number:")
sql_residental(rn,rt,hn)
print(f"DATA SUCCESSFULLY ENTERED OF REDANTIAL SERIAL NUMBER:\n
NAME: {rn}")
print("IF YOU WANT TO CHANGE LAST ENTERED DATA PRESS Y/y")
i4 = input('enter Y/y: ')
if (i4 == 'Y' or i4 == 'y'):
sql_residentalupdate(rn)
elif (i1 == '4' or i1 == 'VIS'):
vn = input('enter name of visitor:')
vt = date_time()
vm = int(input('enter mobile number of the visitor:'))
vr = input('enter reason to visit the area:')
sql_visitor(vn,vt,vm,vr)
print(f"DATA SUCCESSFULLY ENTERED OF VISITOR SERIAL NUMBER:\n
NAME:{vn}")
# CODE TO READ THE ENTERED DATA
74 | P a g e
elif (i == '2' or i == 'R' or i == 'r'):
print('SPECIFY WHICH DATABSE YOU WNAT TO ACCESS')
print(' ')
print("ENTER 1 TO RETRIEVE EMPLOYEE DATA")
print("ENTER 2 TO RETRIEVE VECHICLE DATA")
print("ENTER 3 TO RETRIEVE VISITOR DATA")
print("ENTER 4 TO RETRIEVE RESIDENTAL DATA")
r1 = input('enter number: ')
if r1 == '1':
employee()
elif r1 == '2':
vechicle()
elif r1 == '3':
visitor()
elif r1 == '4':
residental()
75 | P a g e
Output
76 | P a g e
77 | P a g e