-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.js
113 lines (81 loc) · 3.85 KB
/
Code.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function batchShelf() {
// var start = 'AY 67 N5 W7 2005';
// var end = 'PN 171 F56 W35 1998';
// var location = 'scr';
var spread_sheet_name = SpreadsheetApp.getActiveSpreadsheet().getName();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('weeding_criteria');
//find all the items that may not have been filled in correctly.
//get the row number of the last row
//bad call number formatting ; update to include default formatting
var start = sheet.getRange(2,1,1,1).getValues();
var end = sheet.getRange(2,2,1,1).getValues();
var location = sheet.getRange(2,3,1,1).getValues();
//check for empty variables and break if empty
if (start && end && location){
Logger.log("vars have data")
}
else{
Logger.log("empty vars")
Browser.msgBox("empty call number start, end, or location code. check call numbers or locations")
return
};//end var check
Logger.log(start);
Logger.log(end);
Logger.log(location);
//continue by calling api call to the Sierra api based on location and call number range
//logged above in logger values
var url = 'http://ulblwebt02.lib.miamioh.edu/~bomanca/collection/floyd.php?'
+ 'location=' + location + '&' + 'start=' + start + '&' + 'end=' + end;
url = encodeURI(url);
Logger.log(url);
//bad url; problem has to do with formatting of call numbers into variables
var result = UrlFetchApp.fetch(url);
//check for empty result variable
if (result == '[]'){
Logger.log("empty vars")
Browser.msgBox("No data returned. Check to make sure call numbers exist within location")
return
}
else{
Logger.log("vars have data")
};//end result var check
var json_data = JSON.parse(result.getContentText());
var payload = JSON.stringify(json_data); //string representation?
Logger.log(json_data);
//new spreadsheet named after the criteria used to create it
var name = start + '-' + end + ' (' + location + ')';
Logger.log(name);
var shelflist = SpreadsheetApp.getActive().insertSheet(name, SpreadsheetApp.getActive().getSheets().length);
var columns = [["item record","item status","call number","author","title","pub year","last checkout date","last checkin date","checkout total","internal use","renewals","date acquired","decision"]];
Logger.log(columns[0].length);
shelflist.getRange(2,1,json_data.length,json_data[0].length).setValues(json_data);
shelflist.getRange(1,1,1,columns[0].length).setValues(columns);
shelflist.setFrozenRows(1);
//return
}//end function batchShelf
function runLocations() {
var locations = 'http://ulblwebt02.lib.miamioh.edu/~bomanca/collection/locations.php';
url = encodeURI(locations)
var result = UrlFetchApp.fetch(url);
var json_data = JSON.parse(result.getContentText());
var payload = JSON.stringify(json_data); //string representation?
Logger.log(json_data);
var name = 'location list';
var list = SpreadsheetApp.getActive().insertSheet(name, SpreadsheetApp.getActive().getSheets().length);
var columns = [["location code","location labal"]];
list.getRange(2,1,json_data.length,json_data[0].length).setValues(json_data);
list.getRange(1,1,1,columns[0].length).setValues(columns);
}//end runLocations
function updateCalls() {
var calls = 'http://ulblwebt02.lib.miamioh.edu/~bomanca/collection/call_numbers.php';
url = encodeURI(calls)
var result = UrlFetchApp.fetch(url);
var json_data = JSON.parse(result.getContentText());
var payload = JSON.stringify(json_data); //string representation?
Logger.log(json_data);
var name = 'Call numbers';
var list = SpreadsheetApp.getActive().insertSheet(name, SpreadsheetApp.getActive().getSheets().length);
var columns = [["Call Numbers"]];
list.getRange(2,1,json_data.length,json_data[0].length).setValues(json_data);
list.getRange(1,1,1,columns[0].length).setValues(columns);
}//end updateCalls