-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrape.js
41 lines (32 loc) · 999 Bytes
/
scrape.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
var fs = require('fs');
var secret = JSON.parse(fs.readFileSync('data/secret.json', encoding='utf8'));
var grid = JSON.parse(fs.readFileSync('data/grid.json', encoding='utf8'));
var foursquare = (require('foursquarevenues'))(secret.CLIENT_ID, secret.CLIENT_SECRET);
function scraping(params, callback){
var paramsTotal = params.length,
paramsParsed = 0,
venues = [];
params.forEach(function(d,i){
foursquare.getVenues(d, function(error, data) {
if (!error) {
venues = venues.concat(data.response.venues)
console.log(i + "/" + paramsTotal)
paramsParsed++
if(paramsParsed == paramsTotal){
callback(venues)
}
}else{
callback(error)
}
});
})
}
scraping(grid, function(data){
fs.writeFile("data/outtest.json", JSON.stringify(data, null, 2), function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
})