Skip to content

Instantly share code, notes, and snippets.

@arwagner
Created December 3, 2016 23:56
Show Gist options
  • Save arwagner/f90b09cbe9fda2e6ee71b4b7a9e6f3d6 to your computer and use it in GitHub Desktop.
Save arwagner/f90b09cbe9fda2e6ee71b4b7a9e6f3d6 to your computer and use it in GitHub Desktop.
console.log(process.argv);
if (process.argv.length != 7){
console.log("Usage: node challenge.js <timestamp> <status> <challenger> <challengee> <comment>");
process.exit();
}
var data = [process.argv[2], process.argv[3], process.argv[4], process.argv[5], process.argv[6]]
var spreadsheet = require('./spreadsheet');
var challengeTab = 7;
var line = spreadsheet.findFirstBlankLine(challengeTab, function(line){
console.log("line: " + line);
spreadsheet.writeLine(challengeTab, line, data);
});
module.exports = {
findFirstBlankLine: findFirstBlankLine,
writeLine: writeLine
}
function writeLine(tab, line, data){
var GoogleSpreadsheet = require('google-spreadsheet');
var async = require('async');
var doc = new GoogleSpreadsheet('1qZNvfhekN7NJeR-uQnTR94U62Z16ot7yHCYAPT2ktx4');
async.series([
function setAuth(step) {
var creds = require('/Users/andrew/Dropbox/andrew/Lichess Ladder-16cfc4eecd58.json');
doc.useServiceAccountAuth(creds, step);
},
function getInfoAndWorksheets(step) {
console.log("getting cells");
doc.getCells(tab, {
"min-row": line,
"max-row": line,
"min-col": 1,
"max-col": data.length,
"return-empty": true
}, function(err, cells){
console.log("starting loop");
for (var i = 0; i < data.length; i++){
console.log("loop iteration " + i);
cells[i].value = data[i];
cells[i].save();
}
console.log("done loop");
});
console.log("done getInfo");
}]);
}
function findFirstBlankLine(tab, callBack){
var GoogleSpreadsheet = require('google-spreadsheet');
var async = require('async');
var doc = new GoogleSpreadsheet('1qZNvfhekN7NJeR-uQnTR94U62Z16ot7yHCYAPT2ktx4');
async.series([
function setAuth(step) {
var creds = require('/Users/andrew/Dropbox/andrew/Lichess Ladder-16cfc4eecd58.json');
doc.useServiceAccountAuth(creds, step);
},
function getInfoAndWorksheets(step) {
doc.getCells(tab, {
"min-row": 1,
"max-row": 50,
"min-col": 1,
"max-col": 1,
"return-empty": true
}, function(err, cells){
for (var i = 0; i < cells.length; i++){
var cell = cells[i];
if (cell.value === ""){
callBack(cell.row);
break;
}
}
});
}]);
}
@arwagner
Copy link
Author

arwagner commented Dec 3, 2016

[ 'node',
'/Users/andrew/Dropbox/andrew/code/javascript/bot/challenge.js',
'a',
'b',
'c',
'd',
'e' ]
exiting
line: 8
getting cells
done getInfo
starting loop
loop iteration 0
loop iteration 1
loop iteration 2
loop iteration 3
loop iteration 4
done loop
events.js:85
throw er; // Unhandled 'error' event
^
TypeError: undefined is not a function
at /Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/index.js:629:7
at /Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/index.js:166:15
at Parser. (/Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/node_modules/xml2js/lib/xml2js.js:489:18)
at Parser.emit (events.js:107:17)
at Object.onclosetag (/Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/node_modules/xml2js/lib/xml2js.js:447:26)
at emit (/Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/node_modules/xml2js/node_modules/sax/lib/sax.js:640:35)
at emitNode (/Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/node_modules/xml2js/node_modules/sax/lib/sax.js:645:5)
at closeTag (/Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/node_modules/xml2js/node_modules/sax/lib/sax.js:905:7)
at Object.write (/Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/node_modules/xml2js/node_modules/sax/lib/sax.js:1449:13)
at Parser.exports.Parser.Parser.parseString (/Users/andrew/Dropbox/andrew/code/javascript/bot/node_modules/google-spreadsheet/node_modules/xml2js/lib/xml2js.js:508:31)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment