Last active
August 29, 2015 13:59
-
-
Save zaporylie/10742735 to your computer and use it in GitHub Desktop.
Mentors list generator
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 generateHtmlList() { | |
var offset = 2; | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getSheets()[0]; | |
var range = sheet.getRange(1,1,(sheet.getLastColumn() - offset),3); | |
var data = range.getValues(); | |
var stringToDisplay = ''; | |
for (var i = offset; i < data.length; i++) { | |
stringToDisplay += data[i][1] + ' ('; | |
// Check if profile address exists | |
if ((data[i][2] != null) && (data[i][2] != '#ERROR!')) { | |
stringToDisplay += '<a href="' + data[i][2] + '">' + data[i][0] + '</a>'; | |
} else { | |
stringToDisplay += data[i][0]; | |
} | |
stringToDisplay += '), '; | |
} | |
// Display box with code | |
Browser.msgBox(stringToDisplay); | |
} | |
function getTopUrl(query, extra) { | |
if (query == null) { | |
throw 'Argument required'; | |
} | |
if (extra == null) { | |
extra = 'site:drupal.org inurl:/user/'; | |
} | |
var url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q=' + encodeURI(query + " " + extra); | |
var response = UrlFetchApp.fetch(url); | |
var json = response.getContentText(); | |
var object = Utilities.jsonParse(json); | |
if (object["responseStatus"] == '403') { | |
throw 'Quota Exceeded! Check again later.'; | |
} | |
if (object["responseData"]["results"].length == null) { | |
throw 'No results. Try add second parameter to the function (set alternative query string).'; | |
} | |
return object["responseData"]["results"][0]["unescapedUrl"]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment