mirror of
https://github.com/olexsmir/dotfiles.git
synced 2026-01-15 08:41:34 +02:00
25 lines
No EOL
704 B
Python
Executable file
25 lines
No EOL
704 B
Python
Executable file
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import json,sys,urllib.request,time
|
|
|
|
if len(sys.argv) != 3:
|
|
print("Usage: btc usd,eur,btc nok")
|
|
sys.exit()
|
|
|
|
currencies = sys.argv[1]
|
|
basecurrency = sys.argv[2]
|
|
|
|
currencyurl = "http://freecurrencyrates.com/api/action.php?do=cvals&iso=" + currencies.replace(',','') + "&f=" + basecurrency + "&v=1&s=cbr"
|
|
f = urllib.request.urlopen(currencyurl)
|
|
obj = json.loads(f.read())
|
|
res="";
|
|
for c in currencies.split(','):
|
|
res += c.upper() + ":{:,.2f}".format(1/obj[c.upper()]).replace(',',' ')
|
|
|
|
# some unicode currency code replacement (optional)
|
|
res = res.replace("USD", " $")
|
|
res = res.replace("EUR", " €")
|
|
res = res.replace("BTC", " ")
|
|
|
|
print(res); |