-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (45 loc) · 1.64 KB
/
index.js
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
import express from 'express'
import fetch from 'node-fetch'
var app = express()
app.get("/", function (request, response) {
const KEY = process.env[KEY]
const keyword = "vetrinarian"
const radius = "60000" // meters
const latitude = "44.96334453241309"
const longitude = "-93.42300978160829"
const getPlaces = async () => {
const fetchResponse = await fetch(`https://maps.googleapis.com/maps/api/place/nearbysearch/json?keyword=${keyword}&location=${latitude}%2C${longitude}&radius=${radius}&key=${KEY}`)
.then((fetchResponse) => fetchResponse.json())
return fetchResponse
}
// Google requires a second call to get the full place details including phone and website
const getPlaceDetails = async (id) => {
const fetchResponse = await fetch(`https://maps.googleapis.com/maps/api/place/details/json?placeid=${id}&key=${KEY}`)
.then((fetchResponse) => fetchResponse.json())
return fetchResponse
}
const getData = async () => {
const places = await getPlaces()
const results = places.results
let detailedResults = []
for (let i = 0; i < results.length; i++) {
let result = await getPlaceDetails(results[i].place_id)
detailedResults.push(result)
}
const csv = detailedResults.map(item => {
return ({
name: item.result.name,
phone: item.result.formatted_phone_number,
website: item.result.website,
rating: item.result.rating,
address: item.result.vicinity,
mapUrl: item.result.url,
})
})
console.log('csv', csv)
}
getData()
})
app.listen(10000, function () {
console.log("Started application on port %d", 10000)
});