123456789101112131415161718192021222324 |
- import json
- import requests
- import sys
- def main():
- try:
- n = float(sys.argv[1])
- except IndexError:
- sys.exit("Missing command-line argument")
- except (ValueError, TypeError):
- sys.exit("Command-line argument is not a number")
- try:
- response = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
- data = response.json()
- conversion_rate = float(data['bpi']['USD']['rate'].replace(',', ''))
- except requests.RequestException:
- pass
- print(f"${n * conversion_rate:,.4f}")
- if __name__ == "__main__":
- main()
|