mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-02-25 09:28:39 +00:00
Create Currency
This commit is contained in:
parent
2eb833db84
commit
68ee7130b0
18
Currency
Normal file
18
Currency
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Usage: ./currencyrates.py lookup_currency base_currency. Example: ./currencyrates.py cad usd")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
currency = sys.argv[1]
|
||||||
|
basecurrency = sys.argv[2]
|
||||||
|
|
||||||
|
currencyurl = "http://freecurrencyrates.com/api/action.php?do=cvals&iso=" + currency + "&f=" + basecurrency + "&v=1&s=cbr"
|
||||||
|
f = urllib.request.urlopen(currencyurl)
|
||||||
|
obj = json.loads(f.read())
|
||||||
|
result = "1 " + currency.upper() + " is "
|
||||||
|
result+="{:,.2f}".format(1/obj[currency.upper()]) + " " + basecurrency.upper()
|
||||||
|
|
||||||
|
print(result);
|
Loading…
x
Reference in New Issue
Block a user