Add Costco layer

This commit is contained in:
Chandler Swift 2025-12-20 18:53:46 -06:00
parent 6b72513759
commit 584b41c2a4
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F
4 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,54 @@
#!/usr/bin/env python3
import requests
import json
print("Searching for Costco locations")
headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Priority": "u=0, i",
"Pragma": "no-cache",
"Cache-Control": "no-cache"
}
response = requests.get('https://ecom-api.costco.com/warehouseLocatorMobile/v1/warehouses.json?client_id=45823696-9189-482d-89c3-0c067e477ea1&latitude=0&longitude=0&limit=5000&distanceUnit=km', headers=headers).json()
if not response["context"]["lastPage"]:
raise Exception("Got more than one page")
stores = []
for w in response['warehouses']:
stores.append({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [float(w['address']['longitude']), float(w['address']['latitude'])], # yes, [lon, lat] since it's [x, y]
},
"properties": {
'address': w['address']['line1'] + ' ' + w['address'].get('line2', ''),
'city': w['address']['city'],
'state': w['address'].get('territory', ''),
'zip': w['address']['postalCode'],
'type': 'Warehouse' if w['subType']['code'] == 'No Minor Type' else w['subType']['code'],
'phone': w.get('phone', ''),
'opening date': w['openingDate'],
},
})
print(f"""{len(stores)} locations found""")
geojson = {
"type": "FeatureCollection",
"features": stores,
}
with open("data.geojson", "w") as f:
f.write(json.dumps(geojson))