Created
June 15, 2016 09:07
-
-
Save nrobinson2000/1490ef749aa98c2cb825a46b8e2f55b7 to your computer and use it in GitHub Desktop.
bitcoin-usd-converter.py
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 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("1000 mBits = " + str(ask) + " USD") | |
data.close() | |
balance = raw_input('USD to mBits? ') | |
if balance != '': | |
balance = float(balance) | |
result = balance / ask * 1000 | |
roundedresult = int(result * 100 + 0.5) / 100.0 | |
print(str('{:,.2f}'.format(roundedresult)) + ' mBits') | |
balance = raw_input('mBits to USD? ') | |
if balance != '': | |
balance = float(balance) | |
result = ask / 1000 * 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