I'm trying to use a Google Apps Script class, but I'm having trouble finding information on how to use the classes contained in Apps Scripts and running on the node.
Ex: converter.js
if (process.argv.length < 3) {
console.log('Usage: node ' + process.argv[1] + ' FILENAME');
process.exit(1);
}
// Read the file and print its contents.
var objects;
var fs = require('fs')
, filename = process.argv[2];
function print(item, index){
var sourceLang = 'auto';
var targetLang = 'pt';
var sourceText = 'Traduzir';
//var translatedText = LanguageApp.translate(item.mappings.default.default, sourceLang, targetLang);
//console.log(translatedText);
var url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl="
+ sourceLang + "&tl=" + targetLang + "&dt=t&q=" + encodeURI(sourceText);
var result = JSON.parse(UrlFetchApp.fetch(url).getContentText());
translatedText = result[0][0][0];
console.log(translatedText);
// console.log(item.mappings.default.default);
// console.log(item.mappings.default.short);
}
fs.readFile(filename, 'utf8', function(err, data) {
if (err) throw err;
//console.log('OK: ' + filename);
objects = JSON.parse(data);
objects.forEach(print);
console.log(objects.length);
//console.log(data);
});
When I run with the command:
node conversor.js math_digits.json
Result:
/home/alcance/Área de Trabalho/conversor/conversor.js:23
var result = JSON.parse(UrlFetchApp.fetch(url).getContentText());
^
ReferenceError: UrlFetchApp is not defined
at print (/home/alcance/Área de Trabalho/conversor/conversor.js:23:26)
at Array.forEach (native)
at /home/alcance/Área de Trabalho/conversor/conversor.js:36:11
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
I have a problem with this: