From 2f832fa731947b7a4d48a1f3174227f8dfc2f03a Mon Sep 17 00:00:00 2001 From: Chandler Swift Date: Sat, 29 Nov 2025 21:37:43 -0600 Subject: [PATCH] Fix Cane's spider Prior art: AllThePlaces' implementation: https://github.com/alltheplaces/alltheplaces/blob/35dc669befd05ec065eb1d30dafec2305953ca4d/locations/spiders/raising_canes_us.py https://github.com/alltheplaces/alltheplaces/blob/35dc669befd05ec065eb1d30dafec2305953ca4d/locations/storefinders/yext_answers.py Requested-By: Eric Villnow --- layers/chains/raising-canes/get_data.py | 58 +++++++++++++++++-------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/layers/chains/raising-canes/get_data.py b/layers/chains/raising-canes/get_data.py index dc6e4f6..ec3aaa8 100755 --- a/layers/chains/raising-canes/get_data.py +++ b/layers/chains/raising-canes/get_data.py @@ -4,34 +4,54 @@ import requests import json print("Searching for Raising Cane's locations") -response = requests.get('https://raisingcanes.com/page-data/sq/d/3976656178.json').json() + +all_results = [] +desired_results = 999999 + +while len(all_results) < desired_results: + res = requests.get("https://prod-cdn.us.yextapis.com/v2/accounts/me/search/vertical/query", params={ + "experienceKey": "locator", + "api_key": "6c78315e15b82a7cccbbf3fad5db0958", + "v": "20220511", + "version": "PRODUCTION", + "locale": "en", + "verticalKey": "locations", + "filters": json.dumps({ + "builtin.location": { + "$near": { + "lat": 0, + "lng": 0, + "radius": 100000000, + } + } + }), + "limit": 50, + "offset": len(all_results), + "source": "STANDARD", + }) + desired_results = int(res.json()['response']['resultsCount']) + all_results.extend(res.json()['response']['results']) + print(f"Fetched {len(all_results)}/{desired_results} results…") stores = [] -for s in response['data']['allPrismicStoreLocation']['nodes']: - if s['uid'] == 'ara2': # Not sure what's up with this one: https://raisingcanes.com/locations/ara2/ - continue - elif s['uid'] == 'c524': # Null island? https://raisingcanes.com/locations/c524/ - s['data']['coordinates'] = { - "longitude": -111.9811399, - "latitude": 40.5447361, - } +for s in all_results: stores.append({ "type": "Feature", "geometry": { "type": "Point", - "coordinates": [float(s['data']['coordinates']['longitude']), float(s['data']['coordinates']['latitude'])], # yes, [lon, lat] since it's [x, y] + "coordinates": [float(s['data']['yextDisplayCoordinate']['longitude']), float(s['data']['yextDisplayCoordinate']['latitude'])], # yes, [lon, lat] since it's [x, y] }, "properties": { - 'name': s['data']['external_location_data']['displayName'], - 'nickname': s['data']['external_location_data']['nickname'], - 'address': s['data']['external_location_data']['address1'], - 'city': s['data']['external_location_data']['city'], - 'state': s['data']['external_location_data']['state'], - 'zip': s['data']['external_location_data']['postal_code'], - 'website': f"https://raisingcanes.com/locations/{s['uid']}", - 'opened': s['data']['external_location_data']['birthdate'], - 'hours': s['data']['external_location_data']['hours'], + 'name': s['data']['name'], + 'nickname': s['data']['c_nickname'], + 'address': s['data']['address']['line1'], + 'city': s['data']['address']['city'], + 'state': s['data']['address']['region'], + 'zip': s['data']['address']['postalCode'], + 'website': s['data']['websiteUrl'], + 'opened': s['data']['c_openDate'], + 'hours': s['data']['hours'], }, })