Created
November 5, 2011 23:04
-
-
Save mikz/1342144 to your computer and use it in GitHub Desktop.
Depends on money.js, nodejs, coffeescript and request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request = require('request') | |
money = require('money') | |
fs = require('fs') | |
arguments = process.argv.splice(2) | |
amount = arguments.shift() | |
try | |
loop | |
base = arguments.shift() | |
break if base.length == 3 | |
loop | |
target = arguments.shift() | |
break if target.length == 3 | |
catch error | |
console.log 'Wrong arguments' | |
process.exit() | |
request 'http://openexchangerates.org/latest.json', (error, response, body) -> | |
data = JSON.parse(body) | |
money.rates = data.rates | |
money.base = data.base | |
base = base.toUpperCase() | |
target = target.toUpperCase() | |
console.log "#{amount} #{base} in #{target} is: #{money(amount).from(base).to(target)} #{target}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment