aggiunto modulo wolfram

This commit is contained in:
Enrico Fasoli 2015-04-27 20:34:36 +02:00
parent c758e17280
commit a9ee8ac6ad
2 changed files with 29 additions and 1 deletions

View File

@ -27,7 +27,8 @@
"nightmare": "^1.8.0",
"nodepie": "^0.6.7",
"soupselect": "^0.2.0",
"weak": "^0.4.0"
"weak": "^0.4.0",
"wolfram": "^0.3.1"
},
"scripts": {
"test": "mocha test/ --compilers coffee:coffee-script/register"

27
scripts/wolfram.coffee Normal file
View File

@ -0,0 +1,27 @@
# Description:
# accede a wolfram alpha
#
# Dependencies:
# "wolfram":"0.3.1"
#
# Author:
# Enrico Fasoli (fazo96)
#
module.exports = (robot) ->
if not process.env.WOLFRAM_API_KEY?
console.log 'NO WOLFRAM_API_KEY SET!'
return # no api key, no wolfy
wolfram = require('wolfram').createClient process.env.WOLFRAM_API_KEY
robot.respond /(?:quanto fa|compute|wfa|wolfram) (.+)/i, (res) ->
res.send 'contattando Wolfram Alpha...'
wolfram.query res.match[1], (err, result) ->
if err then return res.send err
#res.send JSON.stringify result
parseSubPod = (subpod) -> subpod.value
parsePod = (pod) ->
'\n=== ' + pod.title + '\n' + pod.subpods.map(parseSubPod).join('\n')
res.send (parsePod(pod) for pod in result).join('')