-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
55 lines (50 loc) · 1.09 KB
/
generate.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
54
55
const axios = require("axios");
const Papaparse = require("papaparse");
function fetchCsv(csv) {
return new Promise((resolve, reject) => {
Papaparse.parse(
csv,
{
complete: resolve,
error: reject,
},
);
});
}
async function main() {
const res = await axios("https://docs.google.com/spreadsheets/d/e/2PACX-1vQt0l5CF2hyN3ajkVS_Lx5zPwi0eZ1bD675FPKyt2tKoYPkNynfSLYw6WOi_j0MQTgSsazlfrxOrGtP/pub?gid=0&single=true&output=csv");
const csv = Papaparse.parse(res.data);
// remove header row
csv.data.shift();
const lines = [];
for (const row of csv.data) {
// remove type column
row.pop();
if (row[1] && row[2]) {
row[1] = parseFloat(row[1]);
row[2] = parseFloat(row[2]);
// lines.push(
// [
// row[0],
// [ row[1], row[2], row[3] ],
// ]
// );
lines.push(
[
row[0],
row[2],
row[1],
row[3],
]
);
}
}
return JSON.stringify(
lines,
null,
2,
);
}
main()
.then(console.log)
.catch(console.error);