From 68ee7130b0894c3fb1c533d1e2363f2c0805ba32 Mon Sep 17 00:00:00 2001 From: The Hash <50315422+th3hash@users.noreply.github.com> Date: Tue, 5 Oct 2021 10:36:55 +0530 Subject: [PATCH] Create Currency --- Currency | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Currency diff --git a/Currency b/Currency new file mode 100644 index 0000000..73abd0a --- /dev/null +++ b/Currency @@ -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);