coinmarketcap- python class for the api on coinmarketcap |
git clone git://git.acid.vegas/coinmarketcap.git |
Log | Files | Refs | Archive | README | LICENSE |
commit e5f75a8235ad6cba9eaf75ed556af9084cbf37d6
parent 9d4eb032737209ed6363f78c16c1ed2fc06849fb Author: acidvegas <acid.vegas@acid.vegas> Date: Wed, 22 Apr 2020 02:57:55 -0400 Fixed null values Diffstat:
|
1 file changed, 10 insertions(+), 1 deletion(-) |
diff --git a/coinmarketcap.py b/coinmarketcap.py @@ -6,6 +6,15 @@ import json import time import zlib +# Find a better way to do this... +def replace_nulls(json_elem): + if isinstance(json_elem, list): + return [replace_nulls(elem) for elem in json_elem] + elif isinstance(json_elem, dict): + return {key: replace_nulls(value) for key, value in json_elem.items()} + else: + return '0' if json_elem is None else json_elem + class CoinMarketCap(object): def __init__(self, api_key): self.api_key = api_key @@ -39,7 +48,7 @@ class CoinMarketCap(object): if time.time() - self.last['ticker'] < 300: return self.cache['ticker'] else: - data = self._api('cryptocurrency/listings/latest?limit=5000') + data = replace_nulls(self._api('cryptocurrency/listings/latest?limit=5000')) self.cache['ticker'] = dict() for item in data: self.cache['ticker'][item['id']] = { |