Created
May 12, 2020 08:32
-
-
Save aahlad-allari/a0b4464356bade6bba074371ac761a0e to your computer and use it in GitHub Desktop.
Google API Sheet Sample Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ##### First Node Code #### // | |
const keys = await UTILS.datasets("GoogleJSONKey", {}); | |
const client = new google.auth.JWT( | |
keys.client_email, | |
null, | |
keys.private_key, | |
[ | |
"https://www.googleapis.com/auth/drive.readonly", | |
"https://www.googleapis.com/auth/spreadsheets" | |
] | |
); | |
const sheetrun = async (cl) => { | |
const gsapi = google.sheets({version:"v4", auth: cl}); | |
const opt = { | |
spreadsheetId: inputs.sheetId, | |
range: inputs.range | |
}; | |
let sheetresp = await gsapi.spreadsheets.values.get(opt); | |
return sheetresp.data.values; | |
}; | |
const res = new Promise(async(resolve,reject)=>{ | |
client.authorize(async (err, tokens)=>{ | |
if(err){ | |
resolve({"error":err}) | |
}else{ | |
resolve({"data":await sheetrun(client)}); | |
} | |
}); | |
}) | |
outputs.content = await res; | |
// ##### Second Node Code #### // | |
let inp = inputs.input.data; | |
let out = []; | |
if(R.contains(inputs.headers,["False", "false", "No", "no"] )){ | |
let header = R.head(inp); | |
header = R.map((x) => { | |
return "Column-"+ x; | |
}, R.range(1, R.length(header)+1 ) ); | |
out= R.map((row) => { | |
return R.zipObj(header, row); | |
}, inp); | |
}else{ | |
let header = R.head(inp); | |
out=R.map((row) => { | |
return R.zipObj(header, row); | |
}, (R.tail(inp))); | |
} | |
outputs.content = out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment