Cs Report
Cs Report
1 UPPAL
HYDERABAD
CLASS : XII A
AISSCE NO. :
KENDRIYA VIDYALAYA NO. 1 UPPAL
CERTIFICATE
Date :
1 Acknowledgement
2 Aim and Introduction
3 Hardware and Software
4 Code
5 Output
6 Bibliography
ACKNOWLEDGEMENT
AIM:
To create a user friendly application that is similar to make
my trip for flights using python and mysql connectivity.
INTRODUCTION:
This project has been developed to know how websites
like www.makemytrip.com work and is written in Python.
To achieve this, Enthought Canopy v2.1.9.3717 which is
an integrated development environment and mysql 5.5
which is a relational database management system are
used.
This program allows the user to view the details of various
flights as per the source and destination, sorted and
filtered according to the user's choice and book tickets on
the basis of their availability. The tickets' prices show the
variation with date of departure and the class chosen. It
also allows the user to check their booking history.
The interactive feature of the program makes it much
more convenient for the user to get flight details and do
further booking if desired.
SOFTWARE AND HARDWARE
APPLICATION
SOFTWARE:
ENTHOUGHT CANOPY v2.1.9.3717
MYSQL 5.5
MS WORD
WINDOWS 10, 8
HARDWARE:
4 GB RAM
STANDARD I/O DEVICES
PREREQUISITES
CODE:
import pymysql as pmy
con=pmy.connect(host='localhost',user='root',passwd='sql')
mycursor=con.cursor()
mycursor.execute('create database flight_db;')
mycursor.execute('use flight_db;')
mycursor.execute('create table ids(id varchar(50) primary
key,Password varchar(21));')
mycursor.execute("insert into ids
values('[email protected]','password1'),('[email protected]','xyz
123');")
mycursor.execute('create table bookings(Customer_id
varchar(50),Flight_no varchar(10),Airline varchar(15),Source
varchar(20),Destination varchar(20),Class
varchar(20),No_of_passengers int(3),Date_of_departure
varchar(15),Price decimal(10,2));')
mycursor.execute('create table Flights(Flight_no varchar(10)
primary key,Airline varchar(15),Source
varchar(20),Departure_time varchar(6),Destination
varchar(20),Arrival_time varchar(6),Duration varchar(8),Price
int(10));')
#Flight_no ,Airline ,From ,Departure_time ,To , Arrival_time
,Duration ,Price
mycursor.execute("insert into flights values('6E-
121','INDIGO','HYDERABAD','22:50','CHENNAI','00:05','1h
15m',2634);")
mycursor.execute("insert into flights values('AI-
546','AIRINDIA','HYDERABAD','21:15','CHENNAI','22:15','1h
00m',2813);")
mycursor.execute("insert into flights values('SG-
732','SPICEJET','HYDERABAD','20:50','CHENNAI','21:55','1h
05m',4052);")
mycursor.execute("insert into flights values('6E-
308','INDIGO','HYDERABAD','04:35','DELHI','06:55','2h
20m',3537);")
mycursor.execute("insert into flights values('AI-
559','AIRINDIA','HYDERABAD','06:40','DELHI','08:50','2h
10m',5963);")
mycursor.execute("insert into flights values('SG-
471','SPICEJET','HYDERABAD','05:50','DELHI','08:05','2h
15m',3944);")
mycursor.execute("insert into flights values('6E-
384','INDIGO','CHENNAI','05:00','HYDERABAD','06:25','1h
25m',3752);")
mycursor.execute("insert into flights values('AI-
545','AIRINDIA','CHENNAI','19:15','HYDERABAD','20:35','1h
20m',2725);")
mycursor.execute("insert into flights values('SG-
346','SPICEJET','CHENNAI','22:30','HYDERABAD','23:35','1h
05m',3229);")
mycursor.execute("insert into flights values('6E-
212','INDIGO','CHENNAI','01:15','DELHI','04:10','2h
55m',7584);")
mycursor.execute("insert into flights values('AI-
143','AIRINDIA','CHENNAI','08:40','DELHI','11:35','2h
55m',9655);")
mycursor.execute("insert into flights values('SG-
104','SPICEJET','CHENNAI','07:00','DELHI','09:50','2h
50m',7582);")
mycursor.execute("insert into flights values('6E-
303','INDIGO','DELHI','06:40','HYDERABAD','08:55','2h
15m',3100);")
mycursor.execute("insert into flights values('AI-
560','AIRINDIA','DELHI','07:05','HYDERABAD','09:10','2h
05m',3574);")
mycursor.execute("insert into flights values('SG-
472','SPICEJET','DELHI','21:10','HYDERABAD','23:25','2h
15m',3099);")
mycursor.execute("insert into flights values('6E-
213','INDIGO','DELHI','02:05','CHENNAI','04:55','2h
50m',6624);")
mycursor.execute("insert into flights values('AI-
420','AIRINDIA','DELHI','17:20','CHENNAI','20:00','2h
40m',8194);")
mycursor.execute("insert into flights values('SG-
107','SPICEJET','DELHI','06:10','CHENNAI','09:00','2h
50m',7645);")
con.commit()
con.close()
TABLES:
Tables like below will be created/modified dynamically
during execution of program as per requirement
Functions:
difference(d): Takes the date of departure as argument and
returns the difference between this date and current date in
number of days.
date_to_tablename(d): Takes the date of departure as argument
and returns a string whose format is such that it can be accepted
as a table’s name in mysql.
create_table(tname): Takes tablename (date of departure in
mysql friendly format) as argument and creates a table with this
name having number of bookings for each flight on this date.
check_availability(tname,f_no,_class,no_p): Takes tablename
(date of departure), flight number, preferred class and number of
passengers as arguments and checks for the availability of the
seats as per the requirements and returns true or false.
count_available(tname,l_flights): Takes tablename (date of
departure) and a list of flight numbers as arguments and displays
number of available seats in these flights on that date.
ids_passwords(): Returns a dictionary of ids and their
passwords currently available in the database(flight_db).
update(tname,_class,no_p,f_no): Takes tablename(date of
departure), class(column name),number of passengers and flight
number as arguments and updates this table with the given
details.
booking(info): Takes a list of information (of a booking that is
done) as argument and inserts this information in bookings table.
CODE
from tabulate import tabulate
import pymysql as pmy
con=pmy.connect(host='localhost',user='root',passwd='sql')
mycursor=con.cursor()
mycursor.execute('use flight_db;')
def date_to_tablename(d):
dd=d[:2]
mm=d[3:5]
yy=d[6:]
tname=dd+'_'+mm+'_'+yy
return str(tname)
def check_availability(tname,f_no,_class,no_p):
i='select '+_class+' from '+tname+" where Flight_no =
'"+f_no+"';"
mycursor.execute(i)
x=list(mycursor.fetchone())
if _class=='Economy':
n=10
else:
n=5
if x[0]==None:
x[0]=0
if (n-x[0])>no_p or (n-x[0])==no_p:
return True
else:
return False
def ids_passwords():
id_d={}
mycursor.execute('select id,password from ids;')
info=mycursor.fetchall()
for i in info:
id_d.update({i[0]:i[1]})
return id_d
headings=['Customer_id','Flight_no','Airline','Source','Destina
tion','Class','No_of_passengers','Date_of_departure','Price']
print("Here's your booking history\n")
print(tabulate(book,headings,tablefmt='psql'))
print('\n1. Browse \n2. Exit')
o=int(input('Choose your option:'))
if o==0 or o==2:
break
elif o==1:
n=2
continue
if n==2: #browse
print('\nEnter details')
print("\nList of places \n -> Hyderabad \n -> Chennai \n
-> Delhi")
date_table=date_to_tablename(dep_date)
delta=difference(dep_date)
price='Price+'+str(16-delta)+'*0.1*Price as Price'
ft='select
Flight_no,Airline,Source,Departure_time,Destination,Arrival_time,
Duration,'+price+' from flights where source="'+f+'" and
destination="'+t+'"'
if (airline_p==1 or airline_p==2 or airline_p==3):
air=air_d[airline_p]
ft=ft+' and airline="'+air+'"'
elif airline_p==4:
ft=ft
else:
a=''
for i in airline_p:
air=air_d[i]
a=a+' or airline="'+air+'"'
ft=ft+' and ('+a[4:]+')'
if sort_p==1:
ft=ft+' order by price asc;'
else:
ft=ft+' order by price desc;'
mycursor.execute(ft)
options=mycursor.fetchall()
headers=['Flight_no','Airline','Source','Departure_time','Desti
nation','Arrival_time','Duration','Price']
table_o=tabulate(options,headers,tablefmt='psql')
print(table_o)
print('* Economy prices dispayed')
print('** +1000 for Premium economy, +2000 for
Business class')
no_options=len(options)
list_flights=()
for i in range(no_options): #list of flights displayed
above
list_flights+=(options[i][0],)
print('\n 1. Proceed for booking \n 2. Check for another
route \n 3. Exit')
next_=int(input('Choose your option:'))
if next_==0 or next_==3:
break
elif next_==2:
continue
elif next_==1:
flightno=input("Enter the flight number:")
if flightno=='0':
break
print("\nClass preference \n 1. Economy \n 2.
Premium economy \n 3. Business class")
class_d={1:'Economy',2:'Premium_economy',3:'Business_cla
ss'}
class_p=int(input('Choose your option:'))
if class_p==0:
break
class_=class_d[class_p]
mycursor.execute('show tables;')
tables=mycursor.fetchall()
myflag=0
for tup in tables:
if str(date_table)==tup[0]:
myflag=1 #datetable exists
count_available(date_table,list_flights) #
print('\n1. Enter new details
\n2. Check another way \n3. Exit')
x=int(input('Choose your
option:'))
if x==3 or x==0:
break
elif x==2:
break
elif x==1:
flightno=input("Enter the
flight number:")
if flightno=='0':
break
print("\nClass preference
\n 1. Economy \n 2. Premium economy \n 3. Business class")
class_d={1:'Economy',2:'Premium_economy',3:'Business_cla
ss'}
print('\n-----------------------------------')
print('Date of departure : ',dep_date)
print('\n-----------------------------------')
print('\n ',airline)
print(' FLIGHT NO : ',flightno)
print('\n From :',f,' ''To :',t)
print('\n FARE SUMMARY ')
print(' BASE FARE :',cost_np)
print(' TAXES :',550)
print(' TOTAL :',cost_total)
print('\n No.of passengers :',no_passengers)
print('-----------------------------------')
pay=input('Press enter to proceed for payment')
if pay=='0':
break
print('Payment done')
update(date_table,class_,no_passengers,flightno)
#updates datetable
print('____________________________________________
____________________________________________________
____________________________________________________
__')
if no==0 or no==3:
break
elif no==1:
continue
elif no==2:
n,a=1,1
continue
print('\nThank you, have a good day!')
con.commit()
con.close()
OUTPUT
BIBLIOGRAPHY