Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
This commit is contained in:
2017-08-25 19:35:41 -04:00
parent 351992e369
commit 83365a3ce3
4 changed files with 7 additions and 4 deletions
+2
View File
@@ -12,3 +12,5 @@ pyquery = "*"
pandas = "*"
html5lib = "*"
bs4 = "*"
requests = "*"
simplejson = "*"
+3 -2
View File
@@ -5,6 +5,7 @@ from pyquery import PyQuery as pq
import time
from collections import OrderedDict
from decimal import Decimal
url = 'https://coinmarketcap.com/currencies/views/all/'
session = requests.Session()
@@ -73,7 +74,7 @@ class Coin():
def btc(self):
coins = get_coins()
rate = coins['btc']['usd']
return float(self.usd / rate)
return Decimal("{0:.8f}".format(self.usd / rate))
def value(self, coin):
"""Example: BTC -> ETH"""
@@ -100,7 +101,7 @@ def get_coins():
name = row[2]
ticker = row[3].lower()
usd = float(row[5][1:].replace(',', ''))
btc = usd / btc_value
btc = Decimal("{0:.8f}".format(usd / btc_value))
coins_db.update({ticker: {'rank': rank, 'name': name, 'ticker': ticker, 'usd': usd, 'btc': btc}})
+1 -1
View File
@@ -110,7 +110,7 @@ def get_exchange_value(coin1, coin2, n):
return jsonify(coin={
# 'name': c.name,
# 'ticker': c.ticker,
'value': v * n,
'value': float(v) * n,
'value.coin': coin2,
'exchange_rate': v
})
+1 -1
View File
@@ -83,7 +83,7 @@
{
"coins": [{% for coin in coins %}
"<strong><a href="/{{ coin['ticker'] }}">{{ coin['ticker'] }}</a></strong>":
{{ coin }},{% endfor %}
{{ coin|tojson }},{% endfor %}
]
}
</pre>