61 lines
1.7 KiB
Python
Executable file
61 lines
1.7 KiB
Python
Executable file
#!/usr/bin/env nix-shell
|
|
#! nix-shell -i python3
|
|
#! nix-shell -p python3 python3Packages.selenium geckodriver
|
|
|
|
import json
|
|
import time
|
|
from selenium import webdriver
|
|
from selenium.webdriver.firefox.options import Options
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
options = Options()
|
|
options.headless = True
|
|
options.add_argument("--headless") # apparently options.headless = True isn't working?
|
|
|
|
driver = webdriver.Firefox(options=options)
|
|
|
|
try:
|
|
url = "https://www.zorbaz.com/locationz"
|
|
driver.get(url)
|
|
|
|
# Wait for POPMENU_APOLLO_STATE to be available
|
|
WebDriverWait(driver, 10).until(
|
|
lambda d: d.execute_script("return typeof POPMENU_APOLLO_STATE !== 'undefined'")
|
|
)
|
|
|
|
apollo_state_json = driver.execute_script("return JSON.stringify(POPMENU_APOLLO_STATE);")
|
|
|
|
finally:
|
|
driver.quit()
|
|
|
|
zorbazez = []
|
|
for k, v in json.loads(apollo_state_json).items():
|
|
if not k.startswith('RestaurantLocation:'):
|
|
continue
|
|
zorbazez.append({
|
|
"type": "Feature",
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [float(v['lng']), float(v['lat'])], # yes, [lon, lat] since it's [x, y]
|
|
},
|
|
"properties": {
|
|
"Phone": v['displayPhone'],
|
|
"Address": v['fullAddress'],
|
|
"Email": v['email'],
|
|
"customLocationContent": v['customLocationContent'],
|
|
"Hours": v['schemaHours'],
|
|
# "openingRanges": [{
|
|
# "__ref": "RestaurantLocationOpeningRange:99114"
|
|
# }],
|
|
},
|
|
})
|
|
|
|
geojson = {
|
|
"type": "FeatureCollection",
|
|
"features": zorbazez,
|
|
}
|
|
|
|
with open("data.geojson", "w") as f:
|
|
f.write(json.dumps(geojson))
|
|
|
|
print(f"{len(zorbazez)} locations found")
|