function doGet() {
try {
var sheet = SpreadsheetApp.openById('1OmL4RVv493CkcHzhVGjvBtF-rDVMUFYEUYSxe_znzV8').getSheetByName('Sheet1');
var data = sheet.getDataRange().getValues();
var headers = data[0];
var rows = data.slice(1);
var notifications = [];
for (var i = 0; i < rows.length; i++) {
// Check if entire row is empty
var isEmpty = rows[i].every(cell => cell === '' || cell === null);
if (isEmpty) continue;
var obj = {};
for (var j = 0; j < headers.length; j++) {
obj[headers[j]] = rows[i][j];
}
notifications.push(obj);
}
// Shuffle
for (var i = notifications.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
[notifications[i], notifications[j]] = [notifications[j], notifications[i]];
}
return ContentService
.createTextOutput(JSON.stringify({
notifications: notifications,
count: notifications.length,
status: 'success',
timestamp: new Date().toISOString()
}))
.setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService
.createTextOutput(JSON.stringify({
notifications: [],
count: 0,
error: err.toString(),
status: 'error'
}))
.setMimeType(ContentService.MimeType.JSON);
}
}