aggiunto modulo wolfram
This commit is contained in:
parent
c758e17280
commit
a9ee8ac6ad
@ -27,7 +27,8 @@
|
|||||||
"nightmare": "^1.8.0",
|
"nightmare": "^1.8.0",
|
||||||
"nodepie": "^0.6.7",
|
"nodepie": "^0.6.7",
|
||||||
"soupselect": "^0.2.0",
|
"soupselect": "^0.2.0",
|
||||||
"weak": "^0.4.0"
|
"weak": "^0.4.0",
|
||||||
|
"wolfram": "^0.3.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha test/ --compilers coffee:coffee-script/register"
|
"test": "mocha test/ --compilers coffee:coffee-script/register"
|
||||||
|
27
scripts/wolfram.coffee
Normal file
27
scripts/wolfram.coffee
Normal 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('')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user