From 4c4b37e74e0db50af0e4571ad14b490acfa50fdc Mon Sep 17 00:00:00 2001 From: Chandler Swift Date: Tue, 4 Jul 2023 00:56:31 -0500 Subject: [PATCH] Add Culver's --- layers/culvers/get_data.py | 70 ++++++++++++++++++++++++++++++++++++++ layers/culvers/layer.js | 24 +++++++++++++ layers/culvers/pin.svg | 63 ++++++++++++++++++++++++++++++++++ layers/index.js | 5 +++ 4 files changed, 162 insertions(+) create mode 100755 layers/culvers/get_data.py create mode 100644 layers/culvers/layer.js create mode 100644 layers/culvers/pin.svg diff --git a/layers/culvers/get_data.py b/layers/culvers/get_data.py new file mode 100755 index 0000000..9d34184 --- /dev/null +++ b/layers/culvers/get_data.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 + +import requests +import json + +print("Searching for Culver's locations") +response = requests.get('https://hosted.where2getit.com/lite?action=getstategeojsonmap&appkey=EC84928C-9C0B-11E4-B999-D8F4B845EC6E').json() + +stores = [] + +state_names = {} +for f in response['states']['features']: + state_names[f['properties']['name']] = f['properties']['regiondesc'] + +for s in response['labels']['features']: + if s['properties']['num_stores'] > 0: + state = s['properties']['name'] + print(f"Searching {state}...", end="") + json_data = { + 'request': { + 'appkey': '1099682E-D719-11E6-A0C4-347BDEB8F1E5', + 'formdata': { + 'geolocs': { + 'geoloc': [ + { + 'addressline': state, + 'state': state_names[state], + }, + ], + }, + 'stateonly': 1, + }, + }, + } + + response = requests.post('https://hosted.where2getit.com/culvers/rest/locatorsearch', json=json_data) + count = 0 + for store in response.json()['response']['collection']: + # I tried a bunch of other things and this is the only one that matched :facepalm: + if "coming soon" in store['name'].lower(): # store['comingsoondate']: # not store['dine_in'] and not store['takeout']: # not store['opendate']: # store['comingsoondate']: + # print(f"{store['name']} not yet open") + continue + stores.append({ + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [float(store['longitude']), float(store['latitude'])], # yes, [lon, lat] since it's [x, y] + }, + "properties": { + 'address': store['address1'], + 'city': store['city'], + 'state': store['state'], + 'zip': store['postalcode'], + 'website': store['url'], + }, + }) + count += 1 + print(count) + if not count == s['properties']['num_stores']: + print(f"Inequal for {state}: {count} != {s['properties']['num_stores']}") + +print(f"""{len(stores)} locations found""") + +geojson = { + "type": "FeatureCollection", + "features": stores, +} + +with open("culvers-data.geojson", "w") as f: + f.write(json.dumps(geojson)) diff --git a/layers/culvers/layer.js b/layers/culvers/layer.js new file mode 100644 index 0000000..0ab1993 --- /dev/null +++ b/layers/culvers/layer.js @@ -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 culversURL from '/data/culvers-data.geojson?url'; // TODO: remove `?url`? +import pinURL from '/layers/culvers/pin.svg?url'; // TODO: remove `?url`? + +const vectorLayer = new VectorLayer({ + source: new VectorSource({ + url: culversURL, + format: new GeoJSON, + }), + style: new Style({ + image: new Icon({ + anchor: [0.5, 1], + src: pinURL, + }), + }), +}); + +export default vectorLayer; diff --git a/layers/culvers/pin.svg b/layers/culvers/pin.svg new file mode 100644 index 0000000..1c1eb18 --- /dev/null +++ b/layers/culvers/pin.svg @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + diff --git a/layers/index.js b/layers/index.js index 149de36..a024e78 100644 --- a/layers/index.js +++ b/layers/index.js @@ -5,6 +5,7 @@ import Stamen from 'ol/source/Stamen.js'; import amtrakLayer from './amtrak/layer.js'; import arenasLayer from './nhl-arenas/layer.js'; import menardsLayer from './menards/layer.js'; +import culversLayer from './culvers/layer.js'; const layerCategories = [ { @@ -61,6 +62,10 @@ const layerCategories = [ name: "Menards", layer: menardsLayer, }, + { + name: "Culver's", + layer: culversLayer, + }, ] } ];