1
mirror of git://git.acid.vegas/coinmarketcap.git synced 2024-11-21 22:26:38 +00:00

Fixed null values

This commit is contained in:
Dionysus 2020-04-22 02:57:55 -04:00
parent 9d4eb03273
commit e5f75a8235
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE

View File

@ -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']] = {