-
Notifications
You must be signed in to change notification settings - Fork 1
/
search_google.py
31 lines (22 loc) · 973 Bytes
/
search_google.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
import requests
import json
import pandas as pd
from datetime import datetime
# API docs: https://developers.google.com/places/web-service/search
def place_search_google(google_maps_api_key, google_input):
url = 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?'
params = dict(
key=google_maps_api_key,
input=google_input, # input required -- so, use 'name' fields retrieved from Yelp & FB searches?
inputtype='textquery',
fields='place_id,name,formatted_address,plus_code,business_status,permanently_closed,types',
locationbias='rectangle:33.450393,-117.286647|34.071474,-114.496120'
)
# TODO: Add try/except & if/else for response == 200
resp = requests.get(url=url, params=params)
data = json.loads(resp.text)
return data
def parse_results_google(results):
df = pd.DataFrame.from_records(results['candidates'])
df['api_call_datetime'] = datetime.now()
return df