Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added cli tool for calais module.

  • Loading branch information...
commit 825c01e9279879c76a6b2bd017cbda73d5d7494b 1 parent 3c657e4
@mcantelon authored
Showing with 57 additions and 0 deletions.
  1. +57 −0 calais.js
View
57 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)
+ }
+})
Please sign in to comment.
Something went wrong with that request. Please try again.