def getReservationDict(): """ A function to read in a database and create a dictionary with the key coming from the first column. The dictionary value is a Reservation() object. The dictionary is returned. """ table = 'reservations' connection = openConnection() curs = connection.cursor() sqlcmd = "SELECT * FROM " + table d = {} curs.execute(sqlcmd) for row in curs.fetchall(): flightData = airlineClasses.Flight(row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10]) reservation = airlineClasses.Reservation(row[0], row[1], flightData) d[reservation.reservationId] = reservation curs.close() connection.close() return d
def getFlightDict(): """ A function to read in a database e and create a dictionary with the key coming from the first column. The dictionary value is a Flight() object. The dictionary is returned. """ table = 'flights' connection = openConnection() curs = connection.cursor() sqlcmd = "SELECT * FROM " + table d = {} curs.execute(sqlcmd) for row in curs.fetchall(): flight = airlineClasses.Flight() flight.id = row[0] flight.flightnum = row[1] flight.departCity = row[2] flight.arriveCity = row[3] flight.departTime = row[4] flight.departDay = row[5] flight.arriveTime = row[6] flight.arriveDay = row[7] flight.cost = row[8] flight.code = row[9] d[flight.id] = flight curs.close() connection.close() return d
def showFlightDetails(flightDict, flightnum): """ A function to display details on a flight. The flightDict and flight number are the arguments. Results are written to standard output """ flight = airlineClasses.Flight() for k in flightDict.keys(): if flightDict[k].flightnum == flightnum: flight = flightDict[k] print 'Flight', flightnum, 'departs on',flight.departDay, flight.departTime, \ 'arrives on', flight.arriveDay, flight.arriveTime
def getFlightDict(): filename = 'C:/Course/1905/Data/flights.csv' dictionary = {} for input in open(filename,'r'): if input: input = input.rstrip() # remove the newline input = input.replace('"','') # replace double quotes with null input = input.split(',') # split at the comma flight = airlineClasses.Flight(int(input[1]),input[2],input[3],input[4], input[5],input[6],input[7],float(input[8]),int(input[9])) index = int(input[0]) # create new object dictionary[index] = flight # store in dictionary return dictionary
def getFlightDict(): dictionary = {} # for input in open(filename3,'r'): import csv for input in csv.reader(open(filename1,'r')): if input: #fait par reader input = input.rstrip() # remove the newline # input = input.replace('"','') # replace double quotes with null # input = input.split(',') # split at the comma flight = airlineClasses.Flight(int(input[1]),input[2],input[3],input[4], input[5],input[6],input[7],float(input[8]),int(input[9])) index = input[0] # create new object dictionary[index] = flight # store in dictionary return dictionary
def getFlightDict(): filename = 'C:/Course/1905/Data/flights.csv' dictionary = {} for input in open(filename,'r'): if input: input = input.rstrip() # remove the newline input = input.replace('"','') # replace double quotes with null input = input.split(',') # split at the comma flight = airlineClasses.Flight( flightnum = int(input[1]), departCity = input[2],arriveCity = input[3], departTime = input[4], departDay = input[5], arriveTime = input[6], arriveDay = input[7], cost = float(input[8]),code = int(input[9])) dictionary[flight.flightnum] = flight # store in dictionary return dictionary