-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotion_restaurant.py
67 lines (54 loc) · 1.72 KB
/
notion_restaurant.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import gmaps
from notion.client import NotionClient
class NotionDB:
def __init__(self):
self.client = NotionClient(os.environ.get('NOTION_KEY'))
self.cv = self.client.get_collection_view(os.environ.get('RESTAURANT_DB'))
self.dct = dict()
self.update_addresses()
return
def query(self):
return self.cv.default_query().execute()
# update coordinates of addresses
def update_addresses(self):
filter_params = [{
'property': 'address',
'comparator': 'is',
'value': ''
}]
filter_result = self.cv.build_query(filter=filter_params).execute()
for row in filter_result:
# only update results that don't have info populated
if row.title and not row.place_id:
data = gmaps.search(row.title)
if data['status'] == 'OK':
info = data['candidates'][0]
row.address = info['formatted_address']
row.lat = info['geometry']['location']['lat']
row.lng = info['geometry']['location']['lng']
row.marker_icon = info['icon']
row.icon = info['icon']
row.place_id = info['place_id']
return
# construct a dict -> json object
def get_info(self, coords):
result = self.query()
for row in result:
if row.place_id and \
row.lat <= coords['north'] and row.lat >= coords['south'] and \
row.lng >= coords['west'] and row.lng <= coords['east']:
json_string = {
'name': row.name,
'address': row.address,
'lat': row.lat,
'lng': row.lng,
# 'marker_icon' : row.marker_icon,
'place_id': row.place_id
}
self.dct[row.place_id] = json_string
details = gmaps.detail_search(row.place_id)
if details['status'] == 'OK':
for x in details['result']:
self.dct[row.place_id].update({x: details['result'][x]})
return self.dct