Skip to content

Instantly share code, notes, and snippets.

@DilwoarH
Last active July 23, 2021 21:19
Show Gist options
  • Save DilwoarH/e579d9cf8c2501f16bf6bca7422c9c95 to your computer and use it in GitHub Desktop.
Save DilwoarH/e579d9cf8c2501f16bf6bca7422c9c95 to your computer and use it in GitHub Desktop.
Prayer times App script
function doGet(e){
if (!e.parameter["google_sheet_id"]) {
var error = JSON.stringify({
"error": "google_sheet_id parameter is required"
});
return ContentService.createTextOutput(error).setMimeType(ContentService.MimeType.JSON);
}
// Change Spread Sheet url
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/" + e.parameter["google_sheet_id"] + "/edit");
// Sheet Name, Chnage Sheet1 to Users in Spread Sheet. Or any other name as you wish
var sheet = ss.getSheetByName("Prayer times");
return prayerTimes(sheet);
}
function prayerTimes(sheet){
var prayerTimes = {};
// collecting data from 2nd Row , 1st column to last row and last column
var rows = sheet.getRange(2,1,sheet.getLastRow()-1, sheet.getLastColumn()).getDisplayValues();
for(var i = 0, l= rows.length; i<l ; i++){
var dataRow = rows[i];
var record = {};
record['date'] = dataRow[0];
record['fajr_begins'] = dataRow[1];
record['fajr_jamaah'] = dataRow[2];
record['sunrise'] = dataRow[3];
record['zuhr_begins'] = dataRow[4];
record['zuhr_jamaah'] = dataRow[5];
record['asr_1_begins'] = dataRow[6];
record['asr_2_begins'] = dataRow[7];
record['asr_jamaah'] = dataRow[8];
record['maghrib_begins'] = dataRow[9];
record['maghrib_jamaah'] = dataRow[10];
record['isha_begins'] = dataRow[11];
record['isha_jamaah'] = dataRow[12];
prayerTimes[record['date']] = record;
}
var result = JSON.stringify(prayerTimes);
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment