Chandler Swift
7957523c3c
This was originally done to make the gitignoring easier, but ended up being somewhat more complex when trying to include files, so they're moving out closer to the point of use.
42 lines
1 KiB
Python
Executable file
42 lines
1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
import re
|
|
import json
|
|
|
|
res = requests.get('https://locations.wafflehouse.com/')
|
|
|
|
content = res.text
|
|
|
|
locations = re.search(r'<script id="__NEXT_DATA__" type="application/json">(.*)</script>', content)[1]
|
|
|
|
locations = json.loads(locations)['props']['pageProps']['locations']
|
|
|
|
stores = []
|
|
|
|
for location in locations:
|
|
stores.append({
|
|
"type": "Feature",
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [float(location['longitude']), float(location['latitude'])], # yes, [lon, lat] since it's [x, y]
|
|
},
|
|
"properties": {
|
|
'address': location['addressLines'][0].title(),
|
|
'city': location['city'].title(),
|
|
'state': location['state'],
|
|
'zip': location['postalCode'],
|
|
'website': location['websiteURL'],
|
|
},
|
|
})
|
|
|
|
geojson = {
|
|
"type": "FeatureCollection",
|
|
"features": stores,
|
|
}
|
|
|
|
with open("data.geojson", "w") as f:
|
|
f.write(json.dumps(geojson))
|
|
|
|
print(f"{len(locations)} locations found")
|