Skip to content

Instantly share code, notes, and snippets.

@brucemcpherson
Created October 4, 2012 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brucemcpherson/3832942 to your computer and use it in GitHub Desktop.
Save brucemcpherson/3832942 to your computer and use it in GitHub Desktop.
Proxy api query using google apps script to get scraperwiki data
// this will return data from a public scraperwiki table as json
// you call like this - ?shortname=xyz&limit=x&fielda=x&fieldy=y etc... where fielda refers to the name of a field in the scraperwiki table
// see ramblings.mcpher.com for more info
function doGet(e) {
// lets decode the arguments
var content = "";
if (!e.parameter) {
content = {error: "parameters not found"} ;
}
else if (!e.parameter.shortname) {
content = {error: "shortname parameter not found", parameters : e } ;
}
else {
// everything else is optional
var lim = e.parameter.limit ? e.parameter.limit : 0;
var s = "";
for (k in e.parameter) {
if (k != "limit" && k != "shortname") {
s = (s ? s + " AND " : " WHERE ") + k + " = '" + e.parameter[k] + "'" ;
}
}
// now we can call up the rest entry
var cr = mcpher.scraperWikiStuff(e.parameter.shortname, undefined ,
undefined , lim ? lim : undefined, s ? s : undefined , false);
if (!cr) {
content = {error: "unable to query " + e.parameter.shortname, parameters: e } ;
}
else {
content = cr.jObject().toNative();
}
}
return ContentService
.createTextOutput(JSON.stringify (content))
.setMimeType(ContentService.MimeType.JSON); ;
}
// this is just an example of calling directly...
function t() {
var e = {parameter:
{shortname : "interpol_wanted_persons",
Nationality : "Malaysia",
limit: 10}
};
doGet(e);
}
@brucemcpherson
Copy link
Author

for more information, see ramblings.mcpher.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment