-
-
Save anupamchugh/b0c732e9d1e2cf5cc3ce35ae795f6e7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
import urllib.request | |
if len(sys.argv) != 3: | |
print("Usage: ./getcurrencyrates.py search_currency base_currency. Example: ./getcurrencyrates.py usd inr") | |
sys.exit() | |
search_currency = sys.argv[1] | |
base_currency = sys.argv[2] | |
currencyurl = "http://freecurrencyrates.com/api/action.php?do=cvals&iso=" + search_currency + "&f=" + base_currency + "&v=1&s=cbr" | |
request = urllib.request.urlopen(currencyurl) | |
obj = json.loads(request.read()) | |
result = "1 " + search_currency.upper() + " equals " | |
result+="{:,.2f}".format(1/obj[search_currency.upper()]) + " " + base_currency.upper() | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment