Skip to content

Instantly share code, notes, and snippets.

@ilkovich
Last active March 11, 2016 13:52
Show Gist options
  • Select an option

  • Save ilkovich/6c1cde1feb60b9af3db5 to your computer and use it in GitHub Desktop.

Select an option

Save ilkovich/6c1cde1feb60b9af3db5 to your computer and use it in GitHub Desktop.
function WA(input_string) {
var apikey = '<Your API Key>'
, url = "http://api.wolframalpha.com/v2/query?input="
+ encodeURIComponent(input_string)
+ "&appid=" + apikey
+ "&format=plaintext"
, response = UrlFetchApp.fetch(url)
, xml = XmlService.parse(response)
, root = xml.getRootElement()
, children = root.getChildren()
, data = []
, elem
;
for (var i = 0; i < children.length; i++) {
elem = children[i].getChild("subpod");
if(elem) {
data.push(elem.getChild("plaintext").getText());
}
}
return data.join("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment