forked from Medium/snowflake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildTracks.js
27 lines (22 loc) · 898 Bytes
/
buildTracks.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
const csv = require("csvtojson");
const fs = require('fs');
const request = require('request')
const csvUrlPath = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQPxELXAmWEoN839yinWlwNBHBFzbBI3c0dx-vZZPV5C-fvIO-IvFJVDcNeLF_CwfLGZdn2siWSbpLc/pub?gid=741775966&single=true&output=csv';
const csvFilePath = './tracks.csv';
csv()
.fromStream(request.get(csvUrlPath))
.then((jsonObj) => {
let resultObj = jsonObj.reduce((acc, curr) => {
let key = Object.keys(curr)[0];
acc[curr[key].id] = curr[key];
return acc;
}, {});
let jsonContent = "export default " + JSON.stringify(resultObj);
fs.writeFile("tracks.js", jsonContent, 'utf8', function (err) {
if (err) {
console.log("An error occured while writing JSON Object to File.");
return console.log(err);
}
console.log("JSON file has been saved.");
});
});