-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape.js
35 lines (32 loc) · 1.15 KB
/
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
//Use this function to scrape all data from the website.
import {getSkaneledenService,} from "./skaneledenService";
import Promise from "bluebird";
import fs from 'fs';
export default function scrapeData(outFile) {
console.log("Preparing to scrape data...");
let skaneledenService = getSkaneledenService();
skaneledenService.getAllTrackDetails()
.then(detailedTracks => Promise.all(
detailedTracks.data.items.map(dTI =>
skaneledenService.getTrackSegmentsDetails(dTI.slug)
.then(detailedTrackSegments => {
return Promise.all(
detailedTrackSegments.data.items.map(dTSI => skaneledenService.getAllTrackSegmentGeo(dTSI.slug)
.then(geo => ({
...dTSI,
geo,
})
)
)
).then(trackSegmentsWithGeo => ({
...dTI,
trackSegmentsWithGeo,
}));
}))
))
.then(tracksAndSegments => {
console.log(`Data extracted! ...Writing to ${outFile}`);
let jsonString = JSON.stringify(tracksAndSegments, null, 2);
fs.writeFileSync(outFile, jsonString);
});
}