Created
April 13, 2021 18:19
-
-
Save al-codaio/417574ba781e28df78eb9fcc8526391f to your computer and use it in GitHub Desktop.
Create a loading bar while you're retrieving results from an API with Google Apps Script
This file contains 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
// Create a loading bar in your Google Sheet using Google Apps Script | |
// Author: Al Chen ([email protected]) | |
// Last Updated: April 13th, 2021 | |
// Notes: Assumes you are using the V8 runtime (https://developers.google.com/apps-script/guides/v8-runtime) | |
// Example Google Sheet: https://docs.google.com/spreadsheets/d/1ngvYKEMunqCVufR10rlK42iENAERp-uyiPN_aiq-MKo/edit?usp=sharing | |
SOURCE_SHEET_ID = 'YOUR_GOOGLE_SHEETS_ID' | |
SOURCE_WORKSHEET_NAME = 'YOUR_WORKSHEET_NAME' | |
function loop() { | |
const ss = SpreadsheetApp.openById(SOURCE_SHEET_ID).getActiveSheet(); | |
const baseUrl = 'https://api.hashify.net/hash/md5/hex?value='; | |
const [header, ...data] = ss.getDataRange().getValues(); | |
for (let i = 0; i < data.length; i++) { | |
let row = data[i]; | |
let keyword = row[header.indexOf("Keyword")]; | |
ss.getRange(1 + i + 1, header.indexOf("Status") + 1).setValue("Fetching..."); | |
SpreadsheetApp.flush(); | |
for (let j = 1; j <=5; j++) { | |
let progress = row[header.indexOf("For Progress")]; | |
ss.getRange(1 + i + 1, header.indexOf("For progress") + 1).setValue(j); | |
SpreadsheetApp.flush(); | |
} | |
let response = UrlFetchApp.fetch(baseUrl + keyword); | |
let hash = JSON.parse(response.getContentText()).Digest; | |
ss.getRange(1 + i + 1, header.indexOf("MD5 hash") + 1).setValue(hash); | |
ss.getRange(1 + i + 1, header.indexOf("Status") + 1).setValue("Done"); | |
SpreadsheetApp.flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment