Skip to content

Instantly share code, notes, and snippets.

@mikz
Created November 5, 2011 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikz/1342144 to your computer and use it in GitHub Desktop.
Save mikz/1342144 to your computer and use it in GitHub Desktop.
Depends on money.js, nodejs, coffeescript and request
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