maps.chandlerswift.com/layers/chains/country-kitchen/get_data.py

51 lines
1.6 KiB
Python
Raw Permalink Normal View History

2023-07-28 06:50:50 -05:00
#!/usr/bin/env python3
import requests
import json
import re
# Stolen from my machine, appears to work; sufficient and necessary to get
# around their firewall apparently?
UA={
"User-Agent": 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0'
}
response = requests.get('https://countrykitchenrestaurants.com/locations/', headers=UA)
data = re.search(r'jQuery\(document\).ready\(function\(\$\) \{var map1 = \$\("#map1"\).maps\((.*)\).data\("wpgmp_maps"\);\}\);', response.text)
data = json.loads(data[1])
locations = []
for location in data['places']:
if "coming soon" in location['title'].lower():
continue
if location['title'] == "Dodgeville, WI":
# currently location['location']['country'] == 'WI', and no location['location']['state'] -- D'oh!
location['location']['state'] = 'WI'
try:
locations.append({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [float(location['location']['lng']), float(location['location']['lat'])], # yes, [lon, lat] since it's [x, y]
},
"properties": {
'address': location['address'],
'city': location['location']['city'],
'state': location['location']['state'],
'zip': location['location']['postal_code'],
},
})
except:
print(location)
geojson = {
"type": "FeatureCollection",
"features": locations,
}
print(len(locations), "locations found")
with open("data.geojson", "w") as f:
f.write(json.dumps(geojson))