Created
April 20, 2022 17:50
-
-
Save woodwardtw/d5b34a28fbdaa14667bc86e29036aab4 to your computer and use it in GitHub Desktop.
NSF data additions in Google Sheets via Google Script and the NSF API
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 writeEstimates() { | |
let ss = SpreadsheetApp.getActiveSpreadsheet(); | |
let sheets = ss.getActiveSheet(); | |
let allIds = sheets.getRange('a2:a100').getValues(); | |
var row = 2; | |
allIds.forEach((element) => { | |
//Logger.log(element[0].toFixed(0)) | |
let estimate = fetchData(element) | |
sheets.getRange("z"+row).setValue(estimate); | |
row++; | |
}) | |
} | |
function fetchData(id){ | |
let url = `https://api.nsf.gov/services/v1/awards.json?id=${id}&printFields=awardee,title,fundsObligatedAmt,date,abstractText,awardee,id,agency,fundProgramName,estimatedTotalAmt`; | |
let response = UrlFetchApp.fetch(url); | |
let json = JSON.parse(response.getContentText()); | |
let est = json.response.award[0].estimatedTotalAmt; | |
return est; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment