maps.chandlerswift.com/layers/chains/culvers/get_data.py

71 lines
2.5 KiB
Python
Raw Normal View History

2023-07-04 00:56:31 -05:00
#!/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("data.geojson", "w") as f:
2023-07-04 00:56:31 -05:00
f.write(json.dumps(geojson))