maps.chandlerswift.com/layers/milwaukee-burger-company/get_data.py

44 lines
1.4 KiB
Python
Raw Normal View History

2023-07-25 17:41:31 -05:00
#!/usr/bin/env python3
import requests
import json
from bs4 import BeautifulSoup
print("Searching for Milwaukee Burger Company locations")
# 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,
}
with open("milwaukee-burger-company-data.geojson", "w") as f:
f.write(json.dumps(geojson))