Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a loading bar while you're retrieving results from an API with Google Apps Script
// Create a loading bar in your Google Sheet using Google Apps Script
// Author: Al Chen (al@coda.io)
// 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