Skip to content

Commit

Permalink
🐛 goingtocamp equipment filter
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Sep 1, 2023
1 parent 32a4115 commit 417b89a
Show file tree
Hide file tree
Showing 12 changed files with 9,825 additions and 5,278 deletions.
2 changes: 1 addition & 1 deletion camply/containers/gtc_api_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ class SearchFilter(CamplyModel):
getDailyAvailability: bool
partySize: int
numEquipment: int
equipmentCategoryId: int
equipmentCategoryId: Optional[int] = None
filterData: List[Any] = []
subEquipmentCategoryId: Optional[int] = None
51 changes: 20 additions & 31 deletions camply/providers/going_to_camp/going_to_camp_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple, Union
from urllib.parse import urlencode

import requests
from fake_useragent import UserAgent
Expand Down Expand Up @@ -240,28 +241,20 @@ def get_reservation_link(
"""
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,
)
)
url = f"https://{rec_area_domain_name}/create-booking/results"
query_params = {
"mapId": map_id,
"bookingCategoryId": 0,
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
"isReserving": True,
"equipmentId": equipment_id,
"subEquipmentId": sub_equipment_id,
"partySize": party_size,
"resourceLocationId": resource_location_id,
}
booking_url = url + "?" + urlencode(query_params)
return booking_url

def find_facilities_per_recreation_area(
self,
Expand Down Expand Up @@ -472,7 +465,9 @@ def _find_matching_resources(
self, rec_area_id: int, search_filter: SearchFilter
) -> Tuple[Dict[int, Dict[int, List[ResourceAvailabilityUnit]]], List[str]]:
results = self._api_request(
rec_area_id, "MAPDATA", search_filter.dict(exclude_unset=True)
rec_area_id,
"MAPDATA",
search_filter.dict(exclude_unset=True, exclude_none=True),
)
result_parsed = AvailabilityResponse(**results)
availability_details = {
Expand Down Expand Up @@ -541,10 +536,10 @@ def list_site_availability(
getDailyAvailability=False,
partySize=1,
numEquipment=1,
equipmentCategoryId=NON_GROUP_EQUIPMENT,
filterData=[],
)
if equipment_type_id:
search_filter.equipmentCategoryId = NON_GROUP_EQUIPMENT
search_filter.subEquipmentCategoryId = equipment_type_id
resources, additional_resources = self._find_matching_resources(
rec_area_id=campground.recreation_area_id, search_filter=search_filter
Expand All @@ -560,13 +555,7 @@ def list_site_availability(
for map_id, resource_details in resources.items():
for resource_id, availability_details in resource_details.items():
availability_enum = availability_details[0].availability
if any(
[
availability_enum == AvailabilityStatuses.AVAILABLE,
availability_enum == AvailabilityStatuses.INVALID
and equipment_type_id is None,
]
):
if availability_enum == AvailabilityStatuses.AVAILABLE:
ar = AvailableResource(resource_id=resource_id, map_id=map_id)
availabilities.append(ar)
return availabilities
Expand Down
12 changes: 6 additions & 6 deletions tests/cli/cassettes/test_goingtocamp_equipment_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interactions:
Connection:
- keep-alive
User-Agent:
- Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/532.0 (KHTML,
like Gecko) Chrome/4.0.212.0 Safari/532.0
- Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.17
(KHTML, like Gecko) Chrome/11.0.655.0 Safari/534.17
method: GET
uri: https://longpoint.goingtocamp.com/api/equipment
response:
Expand All @@ -33,17 +33,17 @@ interactions:
Content-Type:
- application/json; charset=utf-8
Date:
- Thu, 24 Aug 2023 02:02:36 GMT
- Thu, 31 Aug 2023 15:36:35 GMT
Pragma:
- no-cache
Referrer-Policy:
- strict-origin-when-cross-origin
Request-Context:
- appId=cid-v1:03d8b028-e287-44e2-a3af-4195efd11ce4
Set-Cookie:
- .AspNetCore.Antiforgery.3YREhQdkuHQ=CfDJ8Kcxd2mnrChGmVWDGR44_Q5lNBMjn83HKnTfOsXb5WuBppnPRSSWzAOqtlroLxlyXT0KBToVQvRlX9iwo3r2d3jiAx6X_FbtKmBhGrgqybwv8oDKXKyTrx5VnHpv5crY71E6tsrK2uEvNNSZ7xqKkBk;
- .AspNetCore.Antiforgery.3YREhQdkuHQ=CfDJ8Kcxd2mnrChGmVWDGR44_Q54ickGr4Xe-u8lNRx71KaQSDPgqBr2Pcxpcpt-fVwDV15T0xq3yl27OaaV0UL9ApwNA58WvRaTRGHJBgk8xWWUy5VxZnmH9WjhYZAOA4d35x_XXjF7XRJ8fW7SxXAtEP4;
path=/; samesite=strict; httponly
- XSRF-TOKEN=CfDJ8Kcxd2mnrChGmVWDGR44_Q6TIHE-G76soKT_7ZrHperZhe9abn0K1K_Gg6_B-YswH4q-nOICTIKA-rgdyCw_oetoVGAXGaYA8s0IS9lBXo2VZcGLWqn8yP48m4PkdCzMG5_3_7m2rpmqQ42ZEWV4vQc;
- XSRF-TOKEN=CfDJ8Kcxd2mnrChGmVWDGR44_Q5NapQOxRMpm5jGaZTSxBMLLBO3dp5QlotvsvVaPjVbvmQ9epCryXA9R9qp6tBsYnnULWzTQB7w_C6ROFBIgCxHxPQ6eG-GQbaOcdAdOASzq_V5pyD8hpVfpjFLeAaLB40;
path=/; secure
Strict-Transport-Security:
- max-age=31536000
Expand All @@ -60,7 +60,7 @@ interactions:
X-XSS-Protection:
- "1"
x-azure-ref:
- 20230824T020236Z-q15212mfxx66dcpxhvrn2zbt9g000000021g00000000rr1g
- 20230831T153635Z-ttsvts4b5t27d9wfenxn58c1d800000001kg0000000047hm
status:
code: 200
message: OK
Expand Down
Loading

0 comments on commit 417b89a

Please sign in to comment.