Example #1
0
 def return_arrival_time(time_range):
     if type(time_range) != tuple:
         return ConfigurationError(
             "Input to arrival_time must be a tuple of string objects that represent times."
         )
     if not isinstance(time_range[0], time) or not isinstance(
             time_range[1], time):
         return ConfigurationError(
             "Input to arrival_time must be a tuple of string objects that represent times."
         )
     return FlightSearchBuilder(return_arrival_time=time_range)
 def return_departure_time(self, time_range):
     if type(time_range) != tuple:
         return ConfigurationError(
             "Input to arrival_time must be a tuple of string objects that represent times."
         )
     if not isinstance(time_range[0], time) or not isinstance(
             time_range[1], time):
         return ConfigurationError(
             "Input to arrival_time must be a tuple of string objects that represent times."
         )
     self._return_departure_time = time_range
     return self
Example #3
0
def generate_dates_meeting_conditions(start_date, departure_day, return_day, stop_date):
    if not isinstance(start_date, date) or isinstance(start_date, datetime):
        return ConfigurationError("start_date input to generate_dates_meeting_conditions must be a date object")
    if type(departure_day) != int:
        return ConfigurationError("departure_day input to generate_dates_meeting_conditions must be a int")
    if type(return_day) != int:
        return ConfigurationError("return_day input to generate_dates_meeting_conditions must be a int")
    if not isinstance(stop_date, date) or isinstance(stop_date, datetime):
        return ConfigurationError("stop_date input to generate_dates_meeting_conditions must be a date object")

    pairs = []
    start = None
    for day in daterange(start_date, ((stop_date - start_date).days) + 6):
        if day.weekday() == departure_day:
            start = day

        if start and day != start and day.weekday() == return_day:
            pairs.append((start, day))
            start = None

    return pairs
Example #4
0
    def build_legs(flight_data, start, end, start_city, end_city):
        # First find the route from start to end
        departure_route = find_route(flight_data, start, end)
        if not departure_route:
            return ConfigurationError("Couldn't determine route.")
        
        departure_leg = Leg()
        departure_flight_params = generate_leg_params(departure_route)

        departure_leg._flights = departure_flight_params[0]
        departure_leg._departure_time = departure_flight_params[1]
        departure_leg._arrival_time = departure_flight_params[2]

        departure_leg._from_location_code = start
        departure_leg._from_location = start_city
        departure_leg._to_location_code = end
        departure_leg._to_location = end_city

        # Then find the route from end to start
        arrival_route = find_route(flight_data, end, start)
        if not arrival_route:
            return ConfigurationError("Couldn't determine route.")
        
        return_leg = Leg()
        return_flight_params = generate_leg_params(arrival_route)

        return_leg._flights = return_flight_params[0]
        return_leg._departure_time = return_flight_params[1]
        return_leg._arrival_time = return_flight_params[2]

        return_leg._from_location_code = end
        return_leg._from_location = end_city
        return_leg._to_location_code = start
        return_leg._to_location = start_city

        return [departure_leg, return_leg]
    def search(self):
        # validate request
        if not self.request_is_valid():
            return ConfigurationError("Invalid request")

        # build requests
        flight_queries = build_flight_search_queries(self)

        # make request
        trips = []
        for flight_query in flight_queries:
            trip = parse_flight_response(make_api_request(flight_query))
            if trip:
                trips.extend(trip)
            sleep(API_BACKOFF_SECONDS)

        # return trip object
        trips.sort(key=lambda trip: trip.price)
        return trips
Example #6
0
 def allow_layovers(allow_layovers):
     if type(allow_layovers) != bool:
         return ConfigurationError(
             "Input to allow_layovers must be of type bool")
     return FlightSearchBuilder(allow_layovers=allow_layovers)
Example #7
0
 def start_from(start_date):
     if not isinstance(start_date, date):
         return ConfigurationError(
             "Input to start_from must be of type date")
     return FlightSearchBuilder(start_from=start_date)
Example #8
0
 def price_threshold(price):
     if type(price) != float and type(price) != int:
         return ConfigurationError(
             "Input to price_threshold must be of type int or float")
     return FlightSearchBuilder(price_threshold=price)
Example #9
0
 def return_departure_date(return_departure_date):
     if not isinstance(return_departure_date, date):
         return ConfigurationError(
             "Input to departure_date must be of type datetime")
     return FlightSearchBuilder(return_departure_date=return_departure_date)
 def return_departure_date(self, return_departure_date):
     if not isinstance(return_departure_date, date):
         return ConfigurationError(
             "Input to departure_date must be of type datetime")
     self._return_departure_date = return_departure_date
     return self
 def allow_layovers(self, allow_layovers):
     if type(allow_layovers) != bool:
         return ConfigurationError(
             "Input to allow_layovers must be of type boolean")
     self._allow_layovers = allow_layovers
     return self
 def start_from(self, start_date):
     if not isinstance(start_date, date):
         return ConfigurationError(
             "Input to start_from must be of type date")
     self._start_from = start_date
     return self
 def price_threshold(self, price):
     if type(price) != float and type(price) != int:
         return ConfigurationError(
             "Input to price_threshold must be of type int or float")
     self._price_threshold = price
     return self