Add Costco layer
This commit is contained in:
parent
6b72513759
commit
584b41c2a4
4 changed files with 101 additions and 0 deletions
54
layers/chains/costco/get_data.py
Executable file
54
layers/chains/costco/get_data.py
Executable 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))
|
||||||
24
layers/chains/costco/layer.js
Normal file
24
layers/chains/costco/layer.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import VectorLayer from 'ol/layer/Vector';
|
||||||
|
import {Vector as VectorSource} from 'ol/source.js';
|
||||||
|
import GeoJSON from 'ol/format/GeoJSON.js';
|
||||||
|
|
||||||
|
import {Style} from 'ol/style.js';
|
||||||
|
import Icon from 'ol/style/Icon.js';
|
||||||
|
|
||||||
|
import url from './data.geojson?url'; // TODO: remove `?url`?
|
||||||
|
import pin from './pin.svg?url'; // TODO: remove `?url`?
|
||||||
|
|
||||||
|
const vectorLayer = new VectorLayer({
|
||||||
|
source: new VectorSource({
|
||||||
|
url: url,
|
||||||
|
format: new GeoJSON,
|
||||||
|
}),
|
||||||
|
style: new Style({
|
||||||
|
image: new Icon({
|
||||||
|
anchor: [0.5, 1],
|
||||||
|
src: pin,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default vectorLayer;
|
||||||
18
layers/chains/costco/pin.svg
Normal file
18
layers/chains/costco/pin.svg
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
viewBox="0 0 384 512"
|
||||||
|
width="40px"
|
||||||
|
height="30px"
|
||||||
|
version="1.1"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="m 384,192 c 0,87.4 -117,243 -168.3,307.2 -12.3,15.3 -35.1,15.3 -47.4,0 C 116.1,435 0,279.4 0,192 0,85.96 85.96,0 192,0 245.96029,0 294.73775,22.275796 329.62577,58.136607 363.27205,92.721042 384,139.94065 384,192 Z"
|
||||||
|
style="fill:white;fill-opacity:1" />
|
||||||
|
<g
|
||||||
|
id="g1175"
|
||||||
|
transform="scale(12) translate(1,1)"
|
||||||
|
style="stroke-width:1.00260199;stroke-miterlimit:4;stroke-dasharray:none">
|
||||||
|
<path d="M25.4906 5.69636C23.5799 5.15172 21.6335 4.90172 19.6603 4.90172C12.4013 4.90172 5.81205 9.48207 4.67812 15.1874C3.56205 20.7589 8.19598 25.1071 15.2317 25.1071C16.8299 25.1071 20.2228 24.8749 21.7763 24.3303L23.4995 17.0089C21.9013 18.1606 19.9728 18.7946 17.9995 18.8392C15.312 18.8214 13.321 17.1606 13.7406 14.9999C14.1603 12.8392 16.696 11.1785 19.3835 11.1785C21.187 11.1964 22.9281 11.8928 24.2674 13.1249L25.4906 5.69636Z" fill="#E51937"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
|
|
@ -1,3 +1,4 @@
|
||||||
|
import costcoLayer from './costco/layer.js';
|
||||||
import countryKitchenLayer from './country-kitchen/layer.js';
|
import countryKitchenLayer from './country-kitchen/layer.js';
|
||||||
import culversLayer from './culvers/layer.js';
|
import culversLayer from './culvers/layer.js';
|
||||||
import gilibertosLayer from './gilibertos/layer.js';
|
import gilibertosLayer from './gilibertos/layer.js';
|
||||||
|
|
@ -15,6 +16,10 @@ import zorbazLayer from './zorbaz/layer.js';
|
||||||
const chains = {
|
const chains = {
|
||||||
name: "Chains",
|
name: "Chains",
|
||||||
layers: [
|
layers: [
|
||||||
|
{
|
||||||
|
name: "Costco",
|
||||||
|
layer: costcoLayer,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Country Kitchen",
|
name: "Country Kitchen",
|
||||||
layer: countryKitchenLayer,
|
layer: countryKitchenLayer,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue