maps.chandlerswift.com/layers/chains/milwaukee-burger-company/get_data.py
Chandler Swift 7957523c3c
Distribute data with layers instead of data/ dir
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.
2023-07-25 19:14:05 -05:00

44 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
import requests
import json
from bs4 import BeautifulSoup
# 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://milwaukeeburgercompany.com/', headers=UA)
soup = BeautifulSoup(response.text, 'html.parser')
location_lis = soup.select('section#locations ul.location-list > li')
locations = []
for location_li in location_lis:
lon = location_li
locations.append({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [float(location_li['data-lng']), float(location_li['data-lat'])], # yes, [lon, lat] since it's [x, y]
},
"properties": {
'address': location_li.find('dd', class_="street").text,
'city': location_li.find('dd', class_="city-state-zip").text.split(',')[0],
'state': location_li.find('dd', class_="city-state-zip").text.split(', ')[1].split(' ')[0],
'zip': location_li.find('dd', class_="city-state-zip").text.split(' ')[-1],
},
})
geojson = {
"type": "FeatureCollection",
"features": locations,
}
print(len(locations), "locations found")
with open("data.geojson", "w") as f:
f.write(json.dumps(geojson))