Last active
February 22, 2016 12:58
-
-
Save nrobinson2000/c9f970f11e7a24ce3950 to your computer and use it in GitHub Desktop.
bitcoin-converter.py
This file contains hidden or 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
#!/usr/bin/env python | |
import urllib2 | |
def turnFloat(x): | |
result = "" | |
for i in range(len(x)): | |
if str(x[i]).isdigit(): | |
result = result + x[i] | |
if x[i] == ".": | |
result = result + x[i] | |
return float(result) | |
data = urllib2.urlopen("https://api.bitcoinaverage.com/ticker/global/USD/") | |
text = data.readlines() | |
ask_data = text.__getitem__(2) | |
ask = turnFloat(ask_data) | |
print("1,000,000 Bits = " + str(ask) + " USD") | |
data.close() | |
balance = raw_input('USD to Bits? ') | |
if balance != '': | |
balance = float(balance) | |
result = balance / ask * 1000000 | |
roundedresult = int(result * 100 + 0.5) / 100.0 | |
print(str('{:,.2f}'.format(roundedresult)) + ' Bits') | |
balance = raw_input('Bits to USD? ') | |
if balance != '': | |
balance = float(balance) | |
result = ask / 1000000 * balance | |
roundedresult = int(result * 100 + 0.5) / 100.0 | |
print(str('{:,.2f}'.format(roundedresult)) + ' USD') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment