Skip to content

Commit

Permalink
Added cli tool for calais module.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed Jan 27, 2011
1 parent 3c657e4 commit 825c01e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions calais.js
@@ -0,0 +1,57 @@
#!/usr/bin/env node

/*!
* calais
* Copyright(c) 2011 Mike Cantelon
* MIT Licensed
*/

var fs = require('fs')
, Calais = require('./lib/calais').Calais
, argv = require('optimist').argv
, iniparser = require('iniparser')

var home = process.env.HOME

// if HOME not set, die
if (home === undefined) {
console.log('Error: HOME environmental variable not defined.')
process.exit(1)
}

iniparser.parse(home + '/.calais', function(err, data) {

var config = (err) ? false : data

// deal with command line input
if (argv['_'].length == 1) {

var api_key = (argv['k'] && (argv['k'] != true))
? argv['k']
: config.api_key

if (api_key) {

console.log('K:' + api_key)
}
else {

console.log('Please specify an OpenCalais API key using the -k option.')
}

var contents = fs.readFileSync(argv['_'][0])

var calais = new Calais(api_key, {
'cleanResult': true
})
calais.set('content', content)
calais.fetch(function(result) {
console.log(result)
})
}
else {

console.log('Usage: calais <filename>')
process.exit(1)
}
})

0 comments on commit 825c01e

Please sign in to comment.