forked from Medium/snowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.js
39 lines (37 loc) · 1.1 KB
/
parser.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
const csv = require('csvtojson');
const writeFile = require('fs').writeFile;
const path = require('path');
const config = require('./config');
const { google } = require('googleapis');
// const AWS = require('aws-sdk');
// const s3 = new AWS.s3();
const processData = () => {
const sheets = google.sheets({ version: 'v4' });
sheets.spreadsheets.values.get(
{
spreadsheetId: config.spreadsheetId,
range: 'Roles!A:K',
key: config.apiKey
},
(err, res) => {
if (err) return console.log('The API returned an error: ' + err);
const data = res.data.values;
const objectKeys = data.shift().map(header => header.toLowerCase());
const parsedRoles = data.map(rawRole => {
let role = {};
objectKeys.forEach((key, index) => {
role[key] = index > 1 ? parseInt(rawRole[index]) : rawRole[index];
});
return role;
});
writeFile(
`static/roles.json`,
JSON.stringify({ hudlRoles: parsedRoles }),
error => {
console.log('Parsed Google Sheet to JSON');
}
);
}
);
};
processData();