Skip to content

going_to_camp_provider

Going to Camp Web Searching Utilities

GoingToCamp #

Bases: BaseProvider

Going To Camp API provider

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
class GoingToCamp(BaseProvider):
    """
    Going To Camp API provider
    """

    @classmethod
    def find_recreation_areas(
        cls, search_string: Optional[str] = None, **kwargs
    ) -> List[RecreationArea]:
        """
        Find Matching Recreation Areas based on search string

        Parameters
        ----------
        search_string: Optional[str]
            Search Keyword(s)

        Returns
        -------
        filtered_responses: List[RecreationArea]
            Array of Matching Recreation Areas
        """
        if search_string is not None:
            logger.info(f'Searching for Recreation Areas matching: "{search_string}"')

        if not search_string or search_string == "":
            rec_areas = RECREATION_AREAS.values()
            log_sorted_response(rec_areas)
            return rec_areas

        rec_areas = []
        for _, rec_area in RECREATION_AREAS.items():
            if (
                search_string.lower() in rec_area.recreation_area.lower()
                or search_string.lower() in rec_area.recreation_area_location.lower()
            ):
                rec_areas.append(rec_area)

        log_sorted_response(rec_areas)

        return rec_areas

    def rec_area_lookup(self, rec_area_id: int) -> Tuple[str, RecreationArea]:
        """
        Lookup a recreation area by ID

        Parameters
        ----------
        rec_area_id: int
            The recreation area ID to lookup

        Returns
        -------
        domain_name, rec_ara: Tuple[str, RecreationArea]
            The rec area's domain name and the recreation area object
        """
        for domain_name, rec_area in RECREATION_AREAS.items():
            if str(rec_area.recreation_area_id) == str(rec_area_id):
                return domain_name, rec_area

    def find_campgrounds(
        self,
        search_string: Optional[str] = None,
        rec_area_id: Optional[List[int]] = None,
        campground_id: Optional[List[int]] = None,
        campsite_id: Optional[List[int]] = None,
        **kwargs,
    ) -> List[CampgroundFacility]:
        """
        Find Campgrounds Given a Set of Search Criteria

        Parameters
        ----------
        search_string: Optional[str]
            Search Keyword(s)
        rec_area_id: Optional[List[int]]
            Recreation Area ID by which to filter
        campground_id: Optional[List[int]]
            ID of the Campground

        Returns
        -------
        facilities: List[CampgroundFacility]
            Array of Matching Campgrounds
        """
        if rec_area_id in (None, [], ()):
            logger.error(
                "This provider requires --rec-area to be specified when seaching for campsites"
            )
            sys.exit(1)

        return self.find_facilities_per_recreation_area(
            rec_area_id=rec_area_id,
            campground_id=campground_id,
            search_string=search_string,
        )

    def _get_attr_val(self, attribute, attribute_detail) -> any:
        for attr_value in attribute.get("values", []):
            for attribute_enum_detail in attribute_detail.get("values"):
                if attribute_enum_detail["enumValue"] == attr_value:
                    return _fetch_nested_key(
                        attribute_enum_detail, "localizedValues", 0, "displayName"
                    )

    def get_site_details(self, rec_area_id: int, resource_id: int):
        """
        Get the details about a site in a recreation area

        Parameters
        ----------
        rec_area_id: int
            Recreation Area ID by which to filter
        resource_id: int

        Returns
        -------
        details: Dict[str, str]
            The details about the site
        """
        if not hasattr(self, "_attribute_details"):
            self._attribute_details = self._api_request(
                rec_area_id, "ATTRIBUTE_DETAILS"
            )
        attribute_details = self._attribute_details

        site_details = self._api_request(
            rec_area_id, "SITE_DETAILS", {"resourceId": resource_id}
        )
        site_attributes = {}
        for attribute in site_details["definedAttributes"]:
            attribute_detail = attribute_details[
                f"{attribute['attributeDefinitionId']}"
            ]
            attribute_name = _fetch_nested_key(
                attribute_detail, "localizedValues", 0, "displayName"
            )
            attribute_value = attribute.get("value")
            attribute_values = []
            # Attribute a multi-value enum
            if not attribute_value:
                attr_value = self._get_attr_val(attribute, attribute_detail)
                if not attr_value:
                    continue
                attribute_values.append(attr_value)
            else:
                attribute_values.append(f"{attribute_value}")

            site_attributes[attribute_name] = ",".join(attribute_values)
        site_details["site_attributes"] = site_attributes

        return site_details

    def get_reservation_link(
        self,
        rec_area_domain_name,
        resource_location_id,
        map_id,
        equipment_id,
        sub_equipment_id,
        party_size,
        start_date,
        end_date,
    ):
        """
        Generate a URL which a site can be booked

        Returns
        -------
        url: str
            The reservation link URL

        """
        if not sub_equipment_id:
            sub_equipment_id = ""

        return (
            "https://%s/create-booking/results?mapId=%s"
            "&bookingCategoryId=0"
            "&startDate=%s"
            "&endDate=%s"
            "&isReserving=true"
            "&equipmentId=%s"
            "&subEquipmentId=%s"
            "&partySize=%s"
            "&resourceLocationId=%s"
            % (
                rec_area_domain_name,
                map_id,
                start_date.isoformat(),
                end_date.isoformat(),
                equipment_id,
                sub_equipment_id,
                party_size,
                resource_location_id,
            )
        )

    def find_facilities_per_recreation_area(
        self,
        rec_area_id: Optional[Union[List[int], int]] = None,
        campground_id: Optional[Union[List[int], int]] = None,
        search_string: Optional[str] = None,
        **kwargs,
    ) -> List[CampgroundFacility]:
        """
        Find Matching Campsites by Recreation Area

        Parameters
        ----------
        rec_area_id: Optional[Union[List[int], int]]
            Recreation Area ID
        campground_id: Optional[Union[List[int], int]]
            Campground IDs
        search_string: Optional[str]
            A string to search for in the facility name

        Returns
        -------
        campgrounds: List[CampgroundFacility]
            Array of Matching Campsites
        """
        rec_area_id = make_list(rec_area_id, coerce=int)[0]
        logger.info(
            f"Retrieving Facility Information for Recreation Area ID: `{rec_area_id}`."
        )

        rec_area = None
        for _, ra in RECREATION_AREAS.items():
            if str(ra.recreation_area_id) == str(rec_area_id):
                rec_area = ra
        if not rec_area:
            logger.error(f"Recreation area '{rec_area_id}' does not exist.")
            sys.exit(1)

        self.campground_details = {}
        api_response = self._api_request(rec_area_id, "LIST_CAMPGROUNDS")

        filtered_facilities = self._filter_facilities_responses(
            rec_area_id, facilities=api_response
        )

        campgrounds = []
        # Fetch campgrounds details for all facilities
        for camp_details in self._api_request(rec_area_id, "CAMP_DETAILS"):
            self.campground_details[camp_details["resourceLocationId"]] = camp_details

        # If a search string is provided, make sure every facility name contains
        # the search string
        if search_string and search_string not in [[], (), ""]:
            filtered_facilities = [
                f
                for f in filtered_facilities
                if search_string.lower() in f.resource_location_name.lower()
            ]

        for facility in filtered_facilities:
            _, campground_facility = self._process_facilities_responses(
                rec_area, facility=facility
            )
            if not campground_facility:
                continue
            if not campground_id:
                campgrounds.append(campground_facility)
            campground_strings = make_list(campground_id, coerce=str)
            if (
                campground_id
                and str(campground_facility.facility_id) in campground_strings
            ):
                campgrounds.append(campground_facility)
        logger.info(f"{len(campgrounds)} Matching Campgrounds Found")
        log_sorted_response(response_array=campgrounds)
        return campgrounds

    def _hostname_for(self, recreation_area_id: int) -> str:
        for hostname, recreation_area in RECREATION_AREAS.items():
            if str(recreation_area.recreation_area_id) == str(recreation_area_id):
                return hostname
        return None

    def _api_request(
        self,
        rec_area_id: int,
        endpoint_name: str,
        params: Optional[Dict[str, str]] = None,
    ) -> str:
        if params is None:
            params = {}

        hostname = self._hostname_for(rec_area_id)
        endpoint = ENDPOINTS.get(endpoint_name)
        url = None
        if endpoint:
            url = endpoint.format(hostname)
        headers = {
            "User-Agent": UserAgent(browsers=["chrome"]).random,
            "Accept-Language": "en-US,en;q=0.9",
        }
        response = self.session.get(url=url, headers=headers, params=params, timeout=30)
        if response.ok is False:
            error_message = f"Receiving bad data from GoingToCamp API: status_code: {response.status_code}: {response.text}"
            logger.error(error_message)
            raise ConnectionError(error_message)

        return json.loads(response.content)

    def _filter_facilities_responses(
        self, rec_area_id: int, facilities=List[Dict[str, Any]]
    ) -> List[ResourceLocation]:
        """
        Filter Facilities to Actual Reservable Campsites

        Parameters
        ----------
        rec_area_id: int
            Recreation Area ID
        facilities: List[Dict[str, Any]]
            List of facilities

        Returns
        -------
        List[ResourceLocation]
        """
        filtered_facilities = []
        for facil in facilities:
            try:
                location_name = _fetch_nested_key(
                    facil, "localizedValues", 0, "fullName"
                )
                park_alerts = _fetch_nested_key(
                    facil, "park_alerts", "en-US", 0, "messageTitle"
                )
                if not park_alerts:
                    park_alerts = _fetch_nested_key(
                        facil, "park_alerts", "en-CA", 0, "messageTitle"
                    )

                region_name = _fetch_nested_key(facil, "region")

                facility = ResourceLocation(
                    id=None,
                    region_name=region_name if region_name else "",
                    park_alerts=park_alerts,
                    rec_area_id=rec_area_id,
                    resource_categories=facil.get("resourceCategoryIds"),
                    resource_location_id=facil.get("resourceLocationId"),
                    resource_location_name=location_name,
                )
            except ValidationError as ve:
                logger.error("That doesn't look like a valid Campground Facility")
                logger.error(facil)
                raise ProviderSearchError(
                    "Invalid Campground Facility Returned"
                ) from ve

            if not facility.resource_categories:
                continue

            # Resource categories from: /api/resourcecategory
            if any(
                [
                    CAMP_SITE in facility.resource_categories,
                    GROUP_SITE in facility.resource_categories,
                    OVERFLOW_SITE in facility.resource_categories,
                ]
            ):
                filtered_facilities.append(facility)

        return filtered_facilities

    def _process_facilities_responses(
        self, rec_area: RecreationArea, facility: ResourceLocation
    ) -> Tuple[dict, Optional[CampgroundFacility]]:
        """
        Process Facilities Responses to be More Usable

        Parameters
        ----------
        facility: dict

        Returns
        -------
        Tuple[dict, CampgroundFacility]
        """
        self.campground_details[facility.resource_location_id]
        facility.id = _fetch_nested_key(
            self.campground_details, facility.resource_location_id, "mapId"
        )
        if facility.region_name:
            formatted_recreation_area = (
                f"{rec_area.recreation_area}, {facility.region_name}"
            )
        else:
            formatted_recreation_area = f"{rec_area.recreation_area}"

        campground_facility = CampgroundFacility(
            facility_name=facility.resource_location_name,
            recreation_area=formatted_recreation_area,
            facility_id=facility.resource_location_id,
            recreation_area_id=facility.rec_area_id,
            map_id=facility.id,
        )
        return facility, campground_facility

    def _find_matching_resources(self, rec_area_id: int, search_filter: Dict[str, any]):
        results = self._api_request(rec_area_id, "MAPDATA", search_filter)
        availability_details = {
            search_filter["mapId"]: results["resourceAvailabilities"]
        }

        return availability_details, list(results["mapLinkAvailabilities"].keys())

    def list_equipment_types(self, rec_area_id: int) -> Dict[str, int]:
        """
        List equipment types available for a recreation area

        Params
        ------
        rec_area_id: int
            The ID of the recreation area

        Returns
        -------
        types: List[GoingToCampEquipment]
            A list of equipment types available to this rec area
        """
        results = self._api_request(rec_area_id, "LIST_EQUIPMENT")

        equipment_types = []
        # Only allow equipment from non-group equipment category (the 0th
        # element in results)
        for sub_category in results[0]["subEquipmentCategories"]:
            equipment_name = _fetch_nested_key(
                sub_category, "localizedValues", 0, "name"
            )
            equipment_id = sub_category["subEquipmentCategoryId"]
            equipment_types.append(
                GoingToCampEquipment(
                    equipment_name=equipment_name, equipment_type_id=equipment_id
                )
            )

        log_sorted_response(response_array=equipment_types)
        return equipment_types

    def list_site_availability(
        self,
        campground: CampgroundFacility,
        start_date: datetime.date,
        end_date: datetime.date,
        equipment_type_id: Optional[str],
    ) -> List[AvailableResource]:
        """
        Retrieve the Availability for all Sites in a Camp Area

        Sites are filtered on the provided date range and compatible
        equipment.

        Returns
        -------
        available_sites: List[AvailableResource]
            The list of available sites
        """
        search_filter = {
            "mapId": campground.map_id,
            "resourceLocationId": campground.facility_id,
            "bookingCategoryId": 0,
            "startDate": start_date.isoformat(),
            "endDate": end_date.isoformat(),
            "isReserving": True,
            "getDailyAvailability": False,
            "partySize": 1,
            "numEquipment": 1,
            "equipmentCategoryId": NON_GROUP_EQUIPMENT,
            "filterData": [],
        }
        if equipment_type_id:
            search_filter["subEquipmentCategoryId"] = equipment_type_id

        resources, additional_resources = self._find_matching_resources(
            campground.recreation_area_id, search_filter
        )

        # Resources are often deeply nested; fetch nested resources
        for map_id in additional_resources:
            search_filter["mapId"] = map_id
            avail, _ = self._find_matching_resources(
                campground.recreation_area_id, search_filter
            )
            resources.update(avail)

        availabilities = []
        for map_id, resource_details in resources.items():
            for resource_id, availability_details in resource_details.items():
                if availability_details[0]["availability"] == 0:
                    ar = AvailableResource(resource_id=resource_id, map_id=map_id)
                    availabilities.append(ar)

        return availabilities

find_campgrounds(search_string=None, rec_area_id=None, campground_id=None, campsite_id=None, **kwargs) #

Find Campgrounds Given a Set of Search Criteria

Parameters:

Name Type Description Default
search_string Optional[str]

Search Keyword(s)

None
rec_area_id Optional[List[int]]

Recreation Area ID by which to filter

None
campground_id Optional[List[int]]

ID of the Campground

None

Returns:

Name Type Description
facilities List[CampgroundFacility]

Array of Matching Campgrounds

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
def find_campgrounds(
    self,
    search_string: Optional[str] = None,
    rec_area_id: Optional[List[int]] = None,
    campground_id: Optional[List[int]] = None,
    campsite_id: Optional[List[int]] = None,
    **kwargs,
) -> List[CampgroundFacility]:
    """
    Find Campgrounds Given a Set of Search Criteria

    Parameters
    ----------
    search_string: Optional[str]
        Search Keyword(s)
    rec_area_id: Optional[List[int]]
        Recreation Area ID by which to filter
    campground_id: Optional[List[int]]
        ID of the Campground

    Returns
    -------
    facilities: List[CampgroundFacility]
        Array of Matching Campgrounds
    """
    if rec_area_id in (None, [], ()):
        logger.error(
            "This provider requires --rec-area to be specified when seaching for campsites"
        )
        sys.exit(1)

    return self.find_facilities_per_recreation_area(
        rec_area_id=rec_area_id,
        campground_id=campground_id,
        search_string=search_string,
    )

find_facilities_per_recreation_area(rec_area_id=None, campground_id=None, search_string=None, **kwargs) #

Find Matching Campsites by Recreation Area

Parameters:

Name Type Description Default
rec_area_id Optional[Union[List[int], int]]

Recreation Area ID

None
campground_id Optional[Union[List[int], int]]

Campground IDs

None
search_string Optional[str]

A string to search for in the facility name

None

Returns:

Name Type Description
campgrounds List[CampgroundFacility]

Array of Matching Campsites

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
def find_facilities_per_recreation_area(
    self,
    rec_area_id: Optional[Union[List[int], int]] = None,
    campground_id: Optional[Union[List[int], int]] = None,
    search_string: Optional[str] = None,
    **kwargs,
) -> List[CampgroundFacility]:
    """
    Find Matching Campsites by Recreation Area

    Parameters
    ----------
    rec_area_id: Optional[Union[List[int], int]]
        Recreation Area ID
    campground_id: Optional[Union[List[int], int]]
        Campground IDs
    search_string: Optional[str]
        A string to search for in the facility name

    Returns
    -------
    campgrounds: List[CampgroundFacility]
        Array of Matching Campsites
    """
    rec_area_id = make_list(rec_area_id, coerce=int)[0]
    logger.info(
        f"Retrieving Facility Information for Recreation Area ID: `{rec_area_id}`."
    )

    rec_area = None
    for _, ra in RECREATION_AREAS.items():
        if str(ra.recreation_area_id) == str(rec_area_id):
            rec_area = ra
    if not rec_area:
        logger.error(f"Recreation area '{rec_area_id}' does not exist.")
        sys.exit(1)

    self.campground_details = {}
    api_response = self._api_request(rec_area_id, "LIST_CAMPGROUNDS")

    filtered_facilities = self._filter_facilities_responses(
        rec_area_id, facilities=api_response
    )

    campgrounds = []
    # Fetch campgrounds details for all facilities
    for camp_details in self._api_request(rec_area_id, "CAMP_DETAILS"):
        self.campground_details[camp_details["resourceLocationId"]] = camp_details

    # If a search string is provided, make sure every facility name contains
    # the search string
    if search_string and search_string not in [[], (), ""]:
        filtered_facilities = [
            f
            for f in filtered_facilities
            if search_string.lower() in f.resource_location_name.lower()
        ]

    for facility in filtered_facilities:
        _, campground_facility = self._process_facilities_responses(
            rec_area, facility=facility
        )
        if not campground_facility:
            continue
        if not campground_id:
            campgrounds.append(campground_facility)
        campground_strings = make_list(campground_id, coerce=str)
        if (
            campground_id
            and str(campground_facility.facility_id) in campground_strings
        ):
            campgrounds.append(campground_facility)
    logger.info(f"{len(campgrounds)} Matching Campgrounds Found")
    log_sorted_response(response_array=campgrounds)
    return campgrounds

find_recreation_areas(search_string=None, **kwargs) classmethod #

Find Matching Recreation Areas based on search string

Parameters:

Name Type Description Default
search_string Optional[str]

Search Keyword(s)

None

Returns:

Name Type Description
filtered_responses List[RecreationArea]

Array of Matching Recreation Areas

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
@classmethod
def find_recreation_areas(
    cls, search_string: Optional[str] = None, **kwargs
) -> List[RecreationArea]:
    """
    Find Matching Recreation Areas based on search string

    Parameters
    ----------
    search_string: Optional[str]
        Search Keyword(s)

    Returns
    -------
    filtered_responses: List[RecreationArea]
        Array of Matching Recreation Areas
    """
    if search_string is not None:
        logger.info(f'Searching for Recreation Areas matching: "{search_string}"')

    if not search_string or search_string == "":
        rec_areas = RECREATION_AREAS.values()
        log_sorted_response(rec_areas)
        return rec_areas

    rec_areas = []
    for _, rec_area in RECREATION_AREAS.items():
        if (
            search_string.lower() in rec_area.recreation_area.lower()
            or search_string.lower() in rec_area.recreation_area_location.lower()
        ):
            rec_areas.append(rec_area)

    log_sorted_response(rec_areas)

    return rec_areas

Generate a URL which a site can be booked

Returns:

Name Type Description
url str

The reservation link URL

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
def get_reservation_link(
    self,
    rec_area_domain_name,
    resource_location_id,
    map_id,
    equipment_id,
    sub_equipment_id,
    party_size,
    start_date,
    end_date,
):
    """
    Generate a URL which a site can be booked

    Returns
    -------
    url: str
        The reservation link URL

    """
    if not sub_equipment_id:
        sub_equipment_id = ""

    return (
        "https://%s/create-booking/results?mapId=%s"
        "&bookingCategoryId=0"
        "&startDate=%s"
        "&endDate=%s"
        "&isReserving=true"
        "&equipmentId=%s"
        "&subEquipmentId=%s"
        "&partySize=%s"
        "&resourceLocationId=%s"
        % (
            rec_area_domain_name,
            map_id,
            start_date.isoformat(),
            end_date.isoformat(),
            equipment_id,
            sub_equipment_id,
            party_size,
            resource_location_id,
        )
    )

get_site_details(rec_area_id, resource_id) #

Get the details about a site in a recreation area

Parameters:

Name Type Description Default
rec_area_id int

Recreation Area ID by which to filter

required
resource_id int
required

Returns:

Name Type Description
details Dict[str, str]

The details about the site

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
def get_site_details(self, rec_area_id: int, resource_id: int):
    """
    Get the details about a site in a recreation area

    Parameters
    ----------
    rec_area_id: int
        Recreation Area ID by which to filter
    resource_id: int

    Returns
    -------
    details: Dict[str, str]
        The details about the site
    """
    if not hasattr(self, "_attribute_details"):
        self._attribute_details = self._api_request(
            rec_area_id, "ATTRIBUTE_DETAILS"
        )
    attribute_details = self._attribute_details

    site_details = self._api_request(
        rec_area_id, "SITE_DETAILS", {"resourceId": resource_id}
    )
    site_attributes = {}
    for attribute in site_details["definedAttributes"]:
        attribute_detail = attribute_details[
            f"{attribute['attributeDefinitionId']}"
        ]
        attribute_name = _fetch_nested_key(
            attribute_detail, "localizedValues", 0, "displayName"
        )
        attribute_value = attribute.get("value")
        attribute_values = []
        # Attribute a multi-value enum
        if not attribute_value:
            attr_value = self._get_attr_val(attribute, attribute_detail)
            if not attr_value:
                continue
            attribute_values.append(attr_value)
        else:
            attribute_values.append(f"{attribute_value}")

        site_attributes[attribute_name] = ",".join(attribute_values)
    site_details["site_attributes"] = site_attributes

    return site_details

list_equipment_types(rec_area_id) #

List equipment types available for a recreation area

Params#

rec_area_id: int The ID of the recreation area

Returns:

Name Type Description
types List[GoingToCampEquipment]

A list of equipment types available to this rec area

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
def list_equipment_types(self, rec_area_id: int) -> Dict[str, int]:
    """
    List equipment types available for a recreation area

    Params
    ------
    rec_area_id: int
        The ID of the recreation area

    Returns
    -------
    types: List[GoingToCampEquipment]
        A list of equipment types available to this rec area
    """
    results = self._api_request(rec_area_id, "LIST_EQUIPMENT")

    equipment_types = []
    # Only allow equipment from non-group equipment category (the 0th
    # element in results)
    for sub_category in results[0]["subEquipmentCategories"]:
        equipment_name = _fetch_nested_key(
            sub_category, "localizedValues", 0, "name"
        )
        equipment_id = sub_category["subEquipmentCategoryId"]
        equipment_types.append(
            GoingToCampEquipment(
                equipment_name=equipment_name, equipment_type_id=equipment_id
            )
        )

    log_sorted_response(response_array=equipment_types)
    return equipment_types

list_site_availability(campground, start_date, end_date, equipment_type_id) #

Retrieve the Availability for all Sites in a Camp Area

Sites are filtered on the provided date range and compatible equipment.

Returns:

Name Type Description
available_sites List[AvailableResource]

The list of available sites

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
def list_site_availability(
    self,
    campground: CampgroundFacility,
    start_date: datetime.date,
    end_date: datetime.date,
    equipment_type_id: Optional[str],
) -> List[AvailableResource]:
    """
    Retrieve the Availability for all Sites in a Camp Area

    Sites are filtered on the provided date range and compatible
    equipment.

    Returns
    -------
    available_sites: List[AvailableResource]
        The list of available sites
    """
    search_filter = {
        "mapId": campground.map_id,
        "resourceLocationId": campground.facility_id,
        "bookingCategoryId": 0,
        "startDate": start_date.isoformat(),
        "endDate": end_date.isoformat(),
        "isReserving": True,
        "getDailyAvailability": False,
        "partySize": 1,
        "numEquipment": 1,
        "equipmentCategoryId": NON_GROUP_EQUIPMENT,
        "filterData": [],
    }
    if equipment_type_id:
        search_filter["subEquipmentCategoryId"] = equipment_type_id

    resources, additional_resources = self._find_matching_resources(
        campground.recreation_area_id, search_filter
    )

    # Resources are often deeply nested; fetch nested resources
    for map_id in additional_resources:
        search_filter["mapId"] = map_id
        avail, _ = self._find_matching_resources(
            campground.recreation_area_id, search_filter
        )
        resources.update(avail)

    availabilities = []
    for map_id, resource_details in resources.items():
        for resource_id, availability_details in resource_details.items():
            if availability_details[0]["availability"] == 0:
                ar = AvailableResource(resource_id=resource_id, map_id=map_id)
                availabilities.append(ar)

    return availabilities

rec_area_lookup(rec_area_id) #

Lookup a recreation area by ID

Parameters:

Name Type Description Default
rec_area_id int

The recreation area ID to lookup

required

Returns:

Type Description
domain_name, rec_ara: Tuple[str, RecreationArea]

The rec area's domain name and the recreation area object

Source code in camply/providers/going_to_camp/going_to_camp_provider.py
def rec_area_lookup(self, rec_area_id: int) -> Tuple[str, RecreationArea]:
    """
    Lookup a recreation area by ID

    Parameters
    ----------
    rec_area_id: int
        The recreation area ID to lookup

    Returns
    -------
    domain_name, rec_ara: Tuple[str, RecreationArea]
        The rec area's domain name and the recreation area object
    """
    for domain_name, rec_area in RECREATION_AREAS.items():
        if str(rec_area.recreation_area_id) == str(rec_area_id):
            return domain_name, rec_area