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