Created
March 26, 2020 10:15
-
-
Save sudevschiz/3061041526867ff2ef6f1947ef9716d0 to your computer and use it in GitHub Desktop.
In Google Scripts : Fetch data from an API, compare some change and update last updated time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function time_wise_update(){ | |
var getSheet = SpreadsheetApp.getActive().getSheetByName("Sheet1"); | |
var setSheet = SpreadsheetApp.getActive().getSheetByName("Sheet2"); | |
var url = 'https://xxx/data.json'; | |
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true}); | |
var json = response.getContentText(); | |
var data = JSON.parse(json); | |
var ss = data.ss; | |
// For each row, compare all the elements of the JSON | |
var last_row = getSheet.getLastRow(); | |
for(var i = 2; i <= last_row; i = i+1){ | |
var s = getSheet.getRange(i,1); | |
var active = getSheet.getRange(i,5); | |
var l_time = setSheet.getRange(i,6); | |
for(var j=0;j<ss.length;j++){ | |
if(ss[j].state == s.getValue()){ | |
console.log(ss[j].active,active.getValue(),(ss[j].active - active.getValue())) | |
if((ss[j].active - active.getValue()) != 0){ | |
var now = Utilities.formatDate(new Date(), "GMT+05:30", "dd/MM/yyyy HH:mm:ss") ; | |
l_time.setValue(now); | |
console.log(ss[j].state,ss[j].active,s.getValue(),active.getValue(),now) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment