-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
36 lines (30 loc) · 1.14 KB
/
gulpfile.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
const fs = require('fs');
const axios = require('axios');
const sheetID = '1OlhlWdkKMnZbLKhcx8QpZKNqYzB0NBREIlql85QCoGY';
const sheetRange = 'Sheet1!A1:O101'
const file = `data.json`;
const sheetKey = 'AIzaSyCL0DUmFLVTgQtxE68wr1Pps81xVHb9u-s';
// Simple Google Sheet API access
// https://docs.google.com/spreadsheets/d/1OlhlWdkKMnZbLKhcx8QpZKNqYzB0NBREIlql85QCoGY/edit#gid=0
// https://sheets.googleapis.com/v4/spreadsheets/1OlhlWdkKMnZbLKhcx8QpZKNqYzB0NBREIlql85QCoGY/values/Sheet1!A1:V500?key=AIzaSyCL0DUmFLVTgQtxE68wr1Pps81xVHb9u-s
const sheetUrl = `https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values/${sheetRange}?key=${sheetKey}`;
function fetchSheet(cb) {
axios.get(sheetUrl)
.then((response) => {
// handle success
// console.log(`Getting ${sheetUrl}`);
// Write fileName.json file
const str = JSON.stringify(response.data.values);
fs.writeFile(file, str, (error) => {
if (error) console.error(error);
console.log(`${file} written`);
cb();
});
})
.catch((error) => {
// handle error
console.log(error);
});
cb();
}
exports.default = fetchSheet;