Last active
July 16, 2019 04:54
-
-
Save bram-atmire/52fe162554504b4e1471a17773d9447c to your computer and use it in GitHub Desktop.
DSpace helper Google Apps Script to retrieve full text from CORE discovery
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
function onOpen() { | |
SpreadsheetApp.getUi().createMenu("Atmire") | |
.addItem('Find Full Text','findFullText') | |
.addToUi(); | |
} | |
function findFullText() { | |
var yourapikey = "REPLACEWITHYOURAPIKEY"; | |
var sheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var numrows = sheet.getLastRow()+1; | |
for( x=2 ; x<numrows ; x++){ | |
var doi = sheet.getRange("C"+x).getValue(); | |
if (doi){ | |
var url = 'https://api.core.ac.uk/discovery/discover?doi='+doi+'&apiKey='+yourapikey; | |
var options = { | |
'method' : 'get', | |
'contentType': 'application/json', | |
}; | |
var response = UrlFetchApp.fetch(url, options); | |
var json = response.getContentText(); | |
var resultdata = JSON.parse(json); | |
sheet.getRange("D"+x).setValue(resultdata.source); | |
var encodedURI = resultdata.fullTextLink.substring(48); | |
sheet.getRange("E"+x).setValue(decodeURIComponent(encodedURI)); | |
Utilities.sleep(1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment