Exemple #1
0
    def merge_response(self, initial_response, new_response):
        #since it's not the first call to kraken, some kraken's id
        #might not be uniq anymore
        logger = logging.getLogger(__name__)
        self.change_ids(new_response, len(initial_response.journeys))
        if len(new_response.journeys) == 0:
            return

        #if the initial response was an error we remove the error since we have result now
        if initial_response.HasField('error'):
            initial_response.ClearField('error')

        #we don't want to add a journey already there
        tickets_to_add = set()
        for new_j in new_response.journeys:

            if any(are_equals(new_j, old_j) for old_j in initial_response.journeys):
                logger.debug("the journey tag={}, departure={} "
                                         "was already there, we filter it".format(new_j.type, new_j.departure_date_time))
                continue  # already there, we don't want to add it

            initial_response.journeys.extend([new_j])
            for t in new_j.fare.ticket_id:
                tickets_to_add.add(t)

        # we have to add the additional fares too
        # if at least one journey has the ticket we add it
        initial_response.tickets.extend([t for t in new_response.tickets if t.id in tickets_to_add])
Exemple #2
0
 def _remove_already_present_journey(self, alternative_journeys,
                                     tc_journeys):
     logger = logging.getLogger(__name__)
     to_delete = []
     for idx, journey in enumerate(alternative_journeys):
         for journey_tc in tc_journeys:
             if are_equals(journey, journey_tc):
                 to_delete.append(idx)
     logger.debug(
         'remove %s alternative journey already present in TC response: %s',
         len(to_delete), [alternative_journeys[i].type for i in to_delete])
     to_delete.sort(reverse=True)
     for idx in to_delete:
         del alternative_journeys[idx]