-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbitcoin.py
36 lines (31 loc) · 922 Bytes
/
bitcoin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
This python program is for Bitcoin Price Index,
it accepts the number of Bitcoins users want to buy
and displays the current market price.
-- by Mayuresh Choudhary
"""
# Bitcoin Price Index
import requests
import sys
def main():
# requesting
json_ = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
json_ = json_.json()
while True:
try:
if not sys.argv[1]:
raise IndexError
else:
no_bitcoin = float(sys.argv[1])
rate = json_["bpi"]["USD"]["rate_float"]
cost = no_bitcoin * rate
print(f"${cost:,.4f}")
break
except ValueError:
print("Command Line argument not number")
sys.exit(1)
except IndexError:
print("Command Line argument missing")
sys.exit(1)
if __name__ == "__main__":
main()