-
Notifications
You must be signed in to change notification settings - Fork 0
/
htocnlookup.gs
39 lines (35 loc) · 1.24 KB
/
htocnlookup.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function HTlookup() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange();
var app = SpreadsheetApp;
var numRows = data.getNumRows();
var startRow = "2"; //assumes a header row and that OCN is in column 1
var i;
for (var i = 0; i < (numRows - 1) ; i++) {
//lookup https://catalog.hathitrust.org/api/volumes/brief/oclc/424023.json
//resolve https://catalog.hathitrust.org/Record/007407367
var range = sheet.getRange(startRow, 1);
var data = range.getValues();
var ocn = data
if (typeof ocn == 'number') {
var htUrl = "https://catalog.hathitrust.org/api/volumes/brief/oclc/"
var url = htUrl + ocn + ".json";
var results = UrlFetchApp.fetch(url);
var content = results.getContentText();
var json = JSON.parse(content);
var recordId = Object.keys(json.records)[0];
if (recordId) {
var resolve = "https://catalog.hathitrust.org/Record/"
var linkUrl = resolve + recordId
sheet.getRange(startRow, 3).setValue(linkUrl); //assumes OCN in col 1 and something else in col 2
startRow++;
} else {
sheet.getRange(startRow, 3).setValue("No results");
startRow++;
{ continue; }
}
} else
startRow++;
{continue; }
}
}