-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.gs
More file actions
54 lines (42 loc) · 1.63 KB
/
code.gs
File metadata and controls
54 lines (42 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var sheet_id = "YOUR_GOOGLE_SHEET_ID"; // Google Sheet ID
var ss = SpreadsheetApp.openById(sheet_id);
var sheet = ss.getSheets()[0]; // Get the first sheet in the spreadsheet
/**
* Handles HTTP GET requests.
* Expected parameter: ?read=question
*/
function doGet(e) {
var arg = e.parameter.read;
// If no valid parameter is provided
if (arg == undefined){
return ContentService.createTextOutput("error: invalid request");
}
// If the request is for a question, return a new question
if (arg == "question"){
return getIter();
}
// For any other unexpected request
return ContentService.createTextOutput("error: unexpected request");
}
/**
* Finds the next question, marks it as shown, and returns its data.
*/
function getIter() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var row = 2; // Start checking from row 2 (assuming row 1 is header)
// Find the first row in column H without a checkmark
while (sheet.getRange("H" + row).getValue() !== "") {
row++;
}
// Get question data from columns A, B, and G for the current row
var question = sheet.getRange("B" + row).getDisplayValue();
var difficulty = sheet.getRange("G" + row).getDisplayValue();
var question_id = sheet.getRange("A" + row).getDisplayValue();
// Mark this question as used by putting a checkmark in column H
sheet.getRange("H" + row).setValue("✓");
// Prepare the response string
var res = "Question #" + question_id + " Difficulty : " + difficulty + "\n\n" + question;
Logger.log(res);
// Return the result as a plain text HTTP response
return ContentService.createTextOutput(res);
}