Updated Count
Updated Count to cater for multiple sheets
This commit is contained in:
parent
84b22cb929
commit
adfe4d4777
28
index.js
28
index.js
@ -7,14 +7,19 @@ const readline = require('readline').createInterface({
|
|||||||
const config = require('./config.json');
|
const config = require('./config.json');
|
||||||
|
|
||||||
const check = new Promise(function (resolve) {
|
const check = new Promise(function (resolve) {
|
||||||
var count = 0;
|
var count = 0,
|
||||||
|
position = {};
|
||||||
config.apis.forEach(function (document, d) {
|
config.apis.forEach(function (document, d) {
|
||||||
var totalRate = 0;
|
var totalRate = 0;
|
||||||
document.documents.forEach(function (item, i) {
|
document.documents.forEach(function (item, i) {
|
||||||
|
item.sheets.forEach(function (sh, s) {
|
||||||
count += 1;
|
count += 1;
|
||||||
totalRate += (60 / (item.pollRate / 1000));
|
position[d + "" + i + "" + s] = count;
|
||||||
config.apis[d].documents[i].sheets.itemNo = count;
|
|
||||||
});
|
});
|
||||||
|
totalRate += (60 / (item.pollRate / 1000));
|
||||||
|
//config.apis[d].documents[i].sheets.itemNo = count;
|
||||||
|
});
|
||||||
|
config.position = position;
|
||||||
var stdin = process.openStdin();
|
var stdin = process.openStdin();
|
||||||
if (totalRate > 50) {
|
if (totalRate > 50) {
|
||||||
console.log('\n---------- RATE LIMIT WARNING ----------');
|
console.log('\n---------- RATE LIMIT WARNING ----------');
|
||||||
@ -26,18 +31,20 @@ const check = new Promise(function (resolve) {
|
|||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (config.apis.length == count) {
|
} else if (config.apis.length - 1 == d) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
check.then(function () {
|
check.then(function () {
|
||||||
|
console.log(config.position);
|
||||||
|
//process.exit();
|
||||||
console.clear();
|
console.clear();
|
||||||
process.stdout.cursorTo(0, 1);
|
process.stdout.cursorTo(0, 1);
|
||||||
console.log(`Ctrl+C to kill the application.`);
|
console.log(`Ctrl+C to kill the application.`);
|
||||||
config.apis.forEach(api => {
|
config.apis.forEach(function (api, d) {
|
||||||
api.documents.forEach(docs => {
|
api.documents.forEach(function (docs, i) {
|
||||||
const doc = new GoogleSpreadsheet(docs.googleDocId);
|
const doc = new GoogleSpreadsheet(docs.googleDocId);
|
||||||
doc.useApiKey(api.apiKey);
|
doc.useApiKey(api.apiKey);
|
||||||
|
|
||||||
@ -47,17 +54,17 @@ check.then(function () {
|
|||||||
if (!fs.existsSync(`${config.outputFolder}/${doc.title}/`)) {
|
if (!fs.existsSync(`${config.outputFolder}/${doc.title}/`)) {
|
||||||
fs.mkdirSync(`${config.outputFolder}/${doc.title}/`, { recursive: true });
|
fs.mkdirSync(`${config.outputFolder}/${doc.title}/`, { recursive: true });
|
||||||
}
|
}
|
||||||
docs.sheets.forEach(sheet => {
|
docs.sheets.forEach(function (sheet, s) {
|
||||||
(async function () {
|
(async function () {
|
||||||
downloadCSV = await doc.sheetsByTitle[sheet].downloadAsCSV();
|
downloadCSV = await doc.sheetsByTitle[sheet].downloadAsCSV();
|
||||||
fs.writeFile(`${config.outputFolder}/${doc.title}/${sheet}.csv`, downloadCSV, function (err) {
|
fs.writeFile(`${config.outputFolder}/${doc.title}/${sheet}.csv`, downloadCSV, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
}
|
}
|
||||||
const d = new Date();
|
const date = new Date();
|
||||||
process.stdout.cursorTo(0, docs.sheets.itemNo + 2);
|
process.stdout.cursorTo(0, config.position[d + "" + i + "" + s] + 2);
|
||||||
process.stdout.clearLine();
|
process.stdout.clearLine();
|
||||||
console.log(`"${doc.title} - ${sheet}" last updated at ${pad(d.getHours(), 2)}:${pad(d.getMinutes(), 2)}:${pad(d.getSeconds(), 2)}`);
|
console.log(`"${doc.title} - ${sheet}" last updated at ${pad(date.getHours(), 2)}:${pad(date.getMinutes(), 2)}:${pad(date.getSeconds(), 2)}`);
|
||||||
process.stdout.cursorTo(31, 1);
|
process.stdout.cursorTo(31, 1);
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
@ -71,7 +78,6 @@ check.then(function () {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function pad(n, width, z) {
|
function pad(n, width, z) {
|
||||||
z = z || '0';
|
z = z || '0';
|
||||||
n = n + '';
|
n = n + '';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user