initial commit

This commit is contained in:
2026-01-25 15:11:49 -05:00
commit 53e60af0a3
2 changed files with 63 additions and 0 deletions

5
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"recommendations": [
"apenara.gas-intellisense"
]
}

58
main.gs Normal file
View File

@@ -0,0 +1,58 @@
function doGet(e) {
var type = "";
if (e.parameter.type) {
switch (String(e.parameter.type).toLowerCase()) {
case "json":
type = "json";
break;
case "csv":
type = "csv";
break;
default:
type = "csv";
}
} else {
type = "csv";
}
const sheet = SpreadsheetApp.openById("SPREADSHEET_ID") // <-- ID of spreadsheet to scrape
.getsheets()[0]
.getSheetValues(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());
const colNames = data[0].filter((val) => val.toString().length > 0);
const trimRegex = /,*$/;
const blankLineRegex = /^[\s\n\r]*/gm;
var csvRows = new Array();
var jsonContent = {
"time": new Date(Date.now()).toISOString(),
"codes": []
};
for (const row of sheet) {
if (type == "csv") {
csvRows.push(row.join(",").replace(trimRegex, ""));
} else {
if (row[1].toString().length > 0) {
var newObj = {};
row.join().replace(trimRegex, "").split(",").forEach((val, i) => {
newObj[colNames[i]] = val.toString();
});
jsonContent.codes.push(newObj);
}
}
}
const output = ContentService.createTextOutput();
if (type == "csv") {
output.setContent(csvRows.join("\u000A").replace(blankLineRegex, ""));
output.setMimeType(ContentService.MimeType.CSV);
} else {
jsonContent.codes = jsonContent.codes.slice(1)
output.setContent(JSON.stringify(jsonContent));
output.setMimeType(ContentService.MimeType.JSON);
}
return output;
}