Example #1
0
    def _get_perf_id(
        event_id, perf_token=None, usage_date=None, departure_date=None
    ):

        perf_id = '{0}{1}'.format(
            len(event_id), event_id,
        )

        if departure_date:
            perf_id = '{0}d{1}'.format(
                perf_id, date_to_yyyymmdd(departure_date)
            )

        if perf_token:
            perf_id = '{0}p{1}'.format(
                perf_id, perf_token
            )

        elif usage_date:
            perf_id = '{0}u{1}'.format(
                perf_id, date_to_yyyymmdd(usage_date)
            )

        return perf_id
Example #2
0
 def date_slug(self):
     return date_to_yyyymmdd(self.date)
Example #3
0
    def search_events(
        self, keyword=None,
        earliest_date=None, latest_date=None,
        country=None, city=None,
        latitude=None, longitude=None, radius=None,
        source=None, area_code=None, venue_code=None,
        event_code=None, category=None, event_id_list=None,
        page_length=None, page_number=None,
        sort_by=None, auto_date_range=None,
        request_source_info=None, request_extra_info=None,
        request_video_iframe=None, request_cost_range=True,
        request_media=None, request_custom_fields=True,
        request_reviews=None, request_avail_details=None,
        custom_filter_list=None, airport=None, special_offer_only=False,
        mime_text_type=None, max_iterations=None,
    ):
        """Perform event search, returns list of Event objects.

        If no arguments are provided, then the full list of Events
        that are available will be returned.

        Args:
            keyword (string): keyword search key (default None)
            earliest_date (datetime): restrict to Events with Performances
                after this date (default None)
            latest_date (datetime): restrict to Events with Performances
                before this date (default None)
            country (string): ISO 3166-1 country code (default None)
            city (string): TSW city key (default None)
            latitude (float/int/string): (default None)
            longitude (float/int/string): (default None)
            radius (int/string): integer radius from lat/long point in
                km (default None)
            source (string): supplier system name (default None)
            area_code (string): TSW area code (default None)
            venue_code (string): TSW venue code (default None)
            event_code (string): TSW event code (default None)
            category (string): Event category search key (default None)
            event_id_list (list): Event Ids to return (default None)
            page_length (int): for pagination, number of Event objects
                to return (default None)
            page_number (int): for pagination, page number (default None)
            sort_by (string): defines sorting order, either top (best selling),
                user_rating or critic_rating (default None)
            auto_date_range (string): see settings.AUTO_DATE_RANGE for options
                (default None)
            request_source_info (boolean): flag for supplier info
                (default None)
            request_extra_info (boolean): flag for extra info (default None)
            request_video_iframe (boolean): flag for video (default None)
            request_cost_range (boolean): flag for cost range data
                (default True)
            request_media (list): List of strings representing the names
                of the images to request (default None)
            request_custom_fields (boolean): flag for custom fields
                (default True)
            request_reviews (boolean): flag for reviews (default None)
            request_avail_details (boolean): flag for avail_details
                (default None)
            custom_filter_list (list): custom filters to apply (default None)
            airport (string): airport code (default None)
            special_offer_only (boolean): flag for only returning events with
                special offers (default False)
            mime_text_type (string): desired text format for certain fields
                (most common options are 'html' and 'plain') (default None)
            max_iterations (int): used only in conjunction with
                special_offer_only. Sets the maximum number of iterations
                when retrieving special offers to prevent a full product search
                being performed.

        Returns:
            list: List of Event objects
        """

        s_top = None
        s_user_rating = None
        s_critic_rating = None

        if sort_by:
            if sort_by == 'top':
                s_top = True
            elif sort_by == 'user_rating':
                s_user_rating = True
            elif sort_by == 'critic_rating':
                s_critic_rating = True

        if earliest_date or latest_date:

            date_range = ['', '']
            if earliest_date:
                date_range[0] = date_to_yyyymmdd(earliest_date)
            if latest_date:
                date_range[1] = date_to_yyyymmdd(latest_date)

            date_range = ':'.join(date_range)
        else:
            date_range = None

        if auto_date_range in settings.AUTO_DATE_RANGE:
            s_auto_range = auto_date_range
        else:
            s_auto_range = None

        if request_media is None:
            request_media = settings.REQUEST_MEDIA

        if custom_filter_list:
            s_cust_fltr = ' '.join(custom_filter_list)
        else:
            s_cust_fltr = None

        if event_id_list:
            event_token_list = ','.join(event_id_list)
        else:
            event_token_list = None

        crypto_block = self.get_crypto_block(
            method_name='start_session',
            password_required=False
        )

        if self.events:
            self._setup_instance_variables()

        resp_dict = self._do_core_event_search(
            crypto_block=crypto_block,
            upfront_data_token=self.settings['upfront_data_token'],
            s_keys=keyword, s_dates=date_range,
            s_coco=country, s_city=city,
            s_geo_lat=latitude, s_geo_long=longitude,
            s_geo_rad_km=radius, s_src=source, s_area=area_code,
            s_ven=venue_code, s_eve=event_code, s_class=category,
            event_token_list=event_token_list,
            request_source_info=request_source_info,
            request_extra_info=request_extra_info,
            request_video_iframe=request_video_iframe,
            request_cost_range=request_cost_range,
            request_media=request_media,
            request_custom_fields=request_custom_fields,
            request_reviews=request_reviews,
            request_avail_details=request_avail_details,
            s_top=s_top, s_user_rating=s_user_rating,
            s_critic_rating=s_critic_rating, s_auto_range=s_auto_range,
            page_length=page_length, page_number=page_number,
            s_cust_fltr=s_cust_fltr, s_airport=airport,
            special_offer_only=special_offer_only,
            mime_text_type=mime_text_type, max_iterations=max_iterations
        )

        requested_data = {}

        if request_source_info:
            requested_data['source_info'] = True

        if request_extra_info:
            requested_data['extra_info'] = True

        if request_video_iframe:
            requested_data['video_iframe'] = True

        if request_cost_range:
            requested_data['cost_range'] = True

        if request_custom_fields:
            requested_data['custom_fields'] = True

        if request_reviews:
            requested_data['reviews'] = True

        if request_avail_details:
            requested_data['avail_details'] = True

        if request_media:
            requested_data['media'] = {}

            for m in request_media:
                requested_data['media'][m] = True

        events = []

        for core_event in resp_dict['event']:
            # create event objects and append to list
            event = event_objs.Event(
                event_id=core_event.event_token,
                core_event=core_event,
                requested_data=requested_data,
                **self._internal_settings()
            )
            events.append(event)

            if event.city_code:
                self._add_city(event.city_code, event.city_desc)

            if event.country_code:
                self._add_country(event.country_code, event.country_desc)

            if event.categories:
                self._add_categories(event.categories)

            if request_cost_range and event.min_seatprice_float:
                self._min_seatprice_range.append(event.min_seatprice_float)

            if request_custom_fields and event.custom_fields:
                self._add_custom_fields(event.custom_fields)

            if event.custom_filters:
                self._add_custom_filters(event.custom_filters)

        self._set_crypto_block(
            crypto_block=resp_dict['crypto_block'],
            method_name='event_search'
        )

        self.events = events

        return events