←︎ coinmarketcap :: e5f75a8


1
commit e5f75a8235ad6cba9eaf75ed556af9084cbf37d6 (HEAD -> master, origin/master)
2
Author: acidvegas <acid.vegas@acid.vegas>
3
Date:   Wed Apr 22 02:57:55 2020 -0400
4
5
    Fixed null values
6
---
7
 coinmarketcap.py | 11 ++++++++++-
8
 1 file changed, 10 insertions(+), 1 deletion(-)
9
10
diff --git a/coinmarketcap.py b/coinmarketcap.py
11
index 6d8201b..382dc0d 100644
12
--- a/coinmarketcap.py
13
+++ b/coinmarketcap.py
14
@@ -6,6 +6,15 @@ import json
15
 import time
16
 import zlib
17
 
18
+# Find a better way to do this...
19
+def replace_nulls(json_elem):
20
+	if isinstance(json_elem, list):
21
+		return [replace_nulls(elem) for elem in json_elem]
22
+	elif isinstance(json_elem, dict):
23
+		return {key: replace_nulls(value) for key, value in json_elem.items()}
24
+	else:
25
+		return '0' if json_elem is None else json_elem
26
+
27
 class CoinMarketCap(object):
28
 	def __init__(self, api_key):
29
 		self.api_key = api_key
30
@@ -39,7 +48,7 @@ class CoinMarketCap(object):
31
 		if time.time() - self.last['ticker'] < 300:
32
 			return self.cache['ticker']
33
 		else:
34
-			data = self._api('cryptocurrency/listings/latest?limit=5000')
35
+			data = replace_nulls(self._api('cryptocurrency/listings/latest?limit=5000'))
36
 			self.cache['ticker'] = dict()
37
 			for item in data:
38
 				self.cache['ticker'][item['id']] = {