Preparing git repo for final project
This commit is contained in:
24
problems/pset4/bitcoin/bitcoin.py
Normal file
24
problems/pset4/bitcoin/bitcoin.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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()
|
Reference in New Issue
Block a user