Skip to content

Instantly share code, notes, and snippets.

@cmharlow
Created September 2, 2015 19:03
Show Gist options
  • Save cmharlow/833434bce9f6573e8ed8 to your computer and use it in GitHub Desktop.
Save cmharlow/833434bce9f6573e8ed8 to your computer and use it in GitHub Desktop.
function waybackAPIcall(input) {
var APIURL = "http://www.archive.org/wayback/available?url=";
var prefyear = "&timestamp=2008";
var URL = APIURL.concat(input.concat(prefyear));
var data = UrlFetchApp.fetch(URL);
Utilities.sleep(1000);
return(data.getContentText());
}
function availableinIA(input) {
var result = JSON.parse(input);
Utilities.sleep(1000);
return(result.archived_snapshots.closest.available);
}
function IAURL(input) {
var result = JSON.parse(input);
Utilities.sleep(1000);
return(result.archived_snapshots.closest.url);
}
function IAtimestamp(input) {
var result = JSON.parse(input);
var date = result.archived_snapshots.closest.timestamp;
var fulldate = date.substring(0,4).concat('-'.concat(date.substring(5,7).concat('-'.concat(date.substring(8,10)))));
Utilities.sleep(1000);
return fulldate;
}
/* ---------------- HRWA Solr Calls ------------------- */
/* Querying HRWA Solr Index and asking for JSON data in return */
function HRWAsolrSearch(url) {
var solrURL = "http://spatha.cul.columbia.edu:8081/solr-4.7-hrwa/hrwa-asf/select?q=*%3A*&fq=original_url%3A%22";
var solrURLend = "%22&wt=json";
var queryURL = solrURL.concat(url.concat(solrURLend));
var data = UrlFetchApp.fetch(queryURL);
return(data.getContentText());
}
/* Checking Availability of URL in HRWA */
function availableinHRWA(input) {
var resultCheck = input.response.numFound;
if (resultCheck > 0){
return 'TRUE';
}
else {
return 'FALSE';
}
}
/* If in HRWA, retrieving Date of Capture */
function HRWAtimestamp(input) {
var date = input.response.docs[0].date_of_capture_yyyymm;
var fulldate = date.substring(0,4).concat('-'.concat(date.substring(4,7)));
return fulldate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment