diff --git a/Pipfile b/Pipfile index 27f3cde..361c2a1 100644 --- a/Pipfile +++ b/Pipfile @@ -12,3 +12,5 @@ pyquery = "*" pandas = "*" html5lib = "*" bs4 = "*" +requests = "*" +simplejson = "*" diff --git a/scraper.py b/scraper.py index 3d27fa8..27297c7 100644 --- a/scraper.py +++ b/scraper.py @@ -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}}) diff --git a/server.py b/server.py index 21be4f5..0e6f58d 100644 --- a/server.py +++ b/server.py @@ -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 }) diff --git a/templates/index.html b/templates/index.html index ca0eb5b..bd8ce26 100644 --- a/templates/index.html +++ b/templates/index.html @@ -83,7 +83,7 @@ { "coins": [{% for coin in coins %} "{{ coin['ticker'] }}": - {{ coin }},{% endfor %} + {{ coin|tojson }},{% endfor %} ] }