curconv.py 526 B

12345678910111213
  1. #!/usr/bin/env python
  2. import requests, sys, decimal
  3. API_KEY="API_KEY_HERE"
  4. amount = decimal.Decimal(sys.argv[1])
  5. sys.stdout.write(str(amount) + " " + sys.argv[2] + " = ");
  6. if sys.argv[2] == sys.argv[3]:
  7. print(str(amount) + " " + sys.argv[2])
  8. exit()
  9. rates = requests.get("http://data.fixer.io/api/latest", params = { "access_key": API_KEY, "symbols": sys.argv[2] + "," + sys.argv[3] }).json()["rates"]
  10. print(str(decimal.Decimal(rates[sys.argv[3]]) * amount / decimal.Decimal(rates[sys.argv[2]])) + " " + sys.argv[3])