Exemplo n.º 1
0
    def promptForFlightDetails(self, acode_s=None, acode_d=None, date=None):
        """
        Handles user input for source, destination and departure date for searching flights.
        """
        if not acode_s: acode_s = ""
        if not acode_d: acode_d = ""
        if not date: date = ""
        while set([acode_s, acode_d, date]).intersection([""]):
            if acode_s == "":
                src = input(
                    "Enter the source airport ('R' for previous menu): ")
                if src == 'R': self.showMenu()
                acode_s = self.getAcode(src)

            if acode_d == "":
                dst = input(
                    "Enter the destination airport ('R' to re-enter src): ")
                if dst == 'R': self.promptForFlightDetails()
                acode_d = self.getAcode(dst)

            if date == "":
                date = input(
                    "Enter the date of travel in format DD/MM/YYYY ('R' to re-enter dst): "
                )
                if dst == 'R': self.promptForFlightDetails(acode_s=acode_s)
                if not util.validate(date):
                    date = input(
                        "Invalid date. Try again ('R' for previous menu): ")
        return acode_s, acode_d, date
Exemplo n.º 2
0
    def bookingOptions(self, searchResults, acode_s, acode_d, date, passengerCount=1):
        """
        For one-way trip and round trip options.
        """
        # get trip type
        print("")      
        if passengerCount == 1: # default setting
            tripType = input("Book one-way trip (1) or book round-trip (2): ")
        else:
            tripType = "1"

        # One way trip
        if tripType == "1":
            rowSelection = input("Please enter row number of trip you would like to book: ")
            
            l = list(searchResults[int(float(rowSelection)) - 1])
            l.append(date)
            flightDetails = tuple(l)

            # make a booking for each passenger
            for i in range(0,passengerCount):
                if (i == passengerCount-1): # the last passenger
                    self.makeABooking(flightDetails, passengerCount, oneOfMany=False)
                else: self.makeABooking(flightDetails, passengerCount, oneOfMany=True) 

        # Round trip
        elif tripType == "2":
            return_date = input("Please enter return date in format DD/MM/YYYY.\n")
            if not util.validate(return_date): # date is invalid. let's you try twice, then shows you the list of availble flights
                return_date = input("Please enter return date in format DD/MM/YYYY.\n")

            returnFlights = sf.searchFlights(acode_d, acode_s, return_date) # search for return flights

            if returnFlights:
                print ("Here are the return flights that match your query: ")
                
                self.printFlightData(returnFlights); 
                rowSelectionDepart = input("Please enter row number of departure flight from first table: ")
                rowSelectionReturn = input("Please enter row number of return flight from second table: ")

                # add some more flight details to tuple
                twoBookings = []
                l = list(searchResults[int(float(rowSelectionDepart))-1])
                l.append(date)
                flightDetails = tuple(l)
                twoBookings.append(flightDetails)
                l = list(returnFlights[int(float(rowSelectionReturn))-1])
                l.append(return_date)
                returnDetails = tuple(l)
                twoBookings.append(returnDetails)

                self.makeABooking(twoBookings, passengerCount, roundTrip=True) # Round trips are handled differently for bookings!
            else: 
                print("No return flights found, Try again.")

        else: # did not pick 1 or 2, prompt again
            self.bookingOptions(searchResults, acode_s, acode_d, date)
Exemplo n.º 3
0
    def promptForFlightDetails(self, acode_s=None, acode_d=None, date=None):
        """
        Handles user input for source, destination and departure date for searching flights.
        """
        if not acode_s: acode_s = ""
        if not acode_d: acode_d = ""
        if not date: date = ""
        while set([acode_s, acode_d, date]).intersection([""]):
            if acode_s == "":
                src = input("Enter the source airport ('R' for previous menu): ")
                if src == 'R': self.showMenu()
                acode_s = self.getAcode(src) 
            
            if acode_d == "":
                dst = input("Enter the destination airport ('R' to re-enter src): ")
                if dst == 'R': self.promptForFlightDetails()
                acode_d = self.getAcode(dst) 

            if date == "":
                date = input("Enter the date of travel in format DD/MM/YYYY ('R' to re-enter dst): ")
                if dst == 'R': self.promptForFlightDetails(acode_s=acode_s)
                if not util.validate(date):
                    date = input("Invalid date. Try again ('R' for previous menu): ")
        return acode_s, acode_d, date        
Exemplo n.º 4
0
    def bookingOptions(self,
                       searchResults,
                       acode_s,
                       acode_d,
                       date,
                       passengerCount=1):
        """
        For one-way trip and round trip options.
        """
        # get trip type
        print("")
        if passengerCount == 1:  # default setting
            tripType = input("Book one-way trip (1) or book round-trip (2): ")
        else:
            tripType = "1"

        # One way trip
        if tripType == "1":
            rowSelection = input(
                "Please enter row number of trip you would like to book: ")

            l = list(searchResults[int(float(rowSelection)) - 1])
            l.append(date)
            flightDetails = tuple(l)

            # make a booking for each passenger
            for i in range(0, passengerCount):
                if (i == passengerCount - 1):  # the last passenger
                    self.makeABooking(flightDetails,
                                      passengerCount,
                                      oneOfMany=False)
                else:
                    self.makeABooking(flightDetails,
                                      passengerCount,
                                      oneOfMany=True)

        # Round trip
        elif tripType == "2":
            return_date = input(
                "Please enter return date in format DD/MM/YYYY.\n")
            if not util.validate(
                    return_date
            ):  # date is invalid. let's you try twice, then shows you the list of availble flights
                return_date = input(
                    "Please enter return date in format DD/MM/YYYY.\n")

            returnFlights = sf.searchFlights(
                acode_d, acode_s, return_date)  # search for return flights

            if returnFlights:
                print("Here are the return flights that match your query: ")

                self.printFlightData(returnFlights)
                rowSelectionDepart = input(
                    "Please enter row number of departure flight from first table: "
                )
                rowSelectionReturn = input(
                    "Please enter row number of return flight from second table: "
                )

                # add some more flight details to tuple
                twoBookings = []
                l = list(searchResults[int(float(rowSelectionDepart)) - 1])
                l.append(date)
                flightDetails = tuple(l)
                twoBookings.append(flightDetails)
                l = list(returnFlights[int(float(rowSelectionReturn)) - 1])
                l.append(return_date)
                returnDetails = tuple(l)
                twoBookings.append(returnDetails)

                self.makeABooking(
                    twoBookings, passengerCount, roundTrip=True
                )  # Round trips are handled differently for bookings!
            else:
                print("No return flights found, Try again.")

        else:  # did not pick 1 or 2, prompt again
            self.bookingOptions(searchResults, acode_s, acode_d, date)