Created
August 22, 2019 03:12
-
-
Save BraedonWooding/1a436dc393d52317742716c41a42e377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python program to get a set of | |
# places according to your search | |
# query using Google Places API | |
# importing required modules | |
import requests, json | |
# enter your api key here | |
api_key = 'AIzaSyCCBj4ANTOBqfLZ94oPkqkqqXQRiTrHM3o' | |
# url variable store url | |
url = "https://maps.googleapis.com/maps/api/place/textsearch/json?" | |
# The text string on which to search | |
query = input('Search query: ') | |
# get method of requests module | |
# return response object | |
r = requests.get(url + 'query=' + query + | |
'&key=' + api_key) | |
# json method of response object convert | |
# json format data into python format data | |
x = r.json() | |
# now x contains list of nested dictionaries | |
# we know dictionary contain key value pair | |
# store the value of result key in variable y | |
y = x['results'] | |
f = open("out.csv", "w") | |
f.write("name, city, state, lat, long") | |
# keep looping upto lenght of y | |
for d in y: | |
f.write(d['name'] + "," | |
f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment