Add Zorbaz
Requested-By: Isaac
This commit is contained in:
parent
9f79a4054b
commit
a44550dc0c
4 changed files with 102 additions and 0 deletions
61
layers/chains/zorbaz/get_data.py
Executable file
61
layers/chains/zorbaz/get_data.py
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue