-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.py
29 lines (27 loc) · 1.08 KB
/
search.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
import requests, json, pprint
def getPlace(keyword, api_key):
url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
payload = { 'key': api_key, 'query': ('구래동 ' + keyword.strip()).replace(' ', '+') }
data = json.loads(requests.get(url, params=payload).text)['results']
result = []
for place in data:
this = {
'name' : place['name'],
'location' : place['geometry']['location'],
'address' : place['formatted_address']
}
if (this['name'] != 'Gurae-dong') and ('Gurae-dong' in this['address']):
pprint.pprint(this)
if this not in result:
result.append(this)
return result
if __name__ == '__main__':
config = json.loads(open('config.json').read())
api_key = config['api_key']
keywords = config['keywords']
results = []
for keyword in keywords:
print('[*]', keyword)
results += getPlace(keyword, api_key)
with open('places.json', 'w') as file:
json.dump(results, file, indent=4, sort_keys=True, ensure_ascii=False)