Move chains to their own directory
This commit is contained in:
parent
f3f7a21645
commit
c74edcb8c0
21 changed files with 50 additions and 40 deletions
48
layers/chains/kwik-trip/get_data.py
Executable file
48
layers/chains/kwik-trip/get_data.py
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
print("Searching for Kwik Trip locations")
|
||||
response = requests.get('https://www.kwiktrip.com/Maps-Downloads/Store-List')
|
||||
|
||||
# HACK HACK HACK
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
table = soup.find('table') # there's only one, currently; no identifying ID or anything
|
||||
headers = [th.get_text() for th in table.find('thead').find_all('th')]
|
||||
|
||||
# turn it into a reasonable dict
|
||||
raw_stores = []
|
||||
for row in table.find('tbody').find_all('tr'):
|
||||
store = {}
|
||||
for (header, cell) in zip(headers, row.find_all('td')):
|
||||
store[header] = cell.get_text()
|
||||
raw_stores.append(store)
|
||||
print(f"""{len(raw_stores)} locations found""")
|
||||
|
||||
# turn _that_ into GeoJSON Features
|
||||
stores = []
|
||||
for store in raw_stores:
|
||||
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['Address'].title(),
|
||||
'city': store['City'].title(),
|
||||
'state': store['State'],
|
||||
'zip': store['Zip'],
|
||||
'website': f"https://www.kwiktrip.com/locator/store?id={store['Store Number']}",
|
||||
},
|
||||
})
|
||||
|
||||
geojson = {
|
||||
"type": "FeatureCollection",
|
||||
"features": stores,
|
||||
}
|
||||
|
||||
with open("kwik-trip-data.geojson", "w") as f:
|
||||
f.write(json.dumps(geojson))
|
||||
Loading…
Add table
Add a link
Reference in a new issue