mirror of
https://github.com/wassname/libcryptomarket.git
synced 2026-09-09 11:25:52 +08:00
raise error and log api messages
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#!/bin/python
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
API_URL = "https://min-api.cryptocompare.com/data/"
|
||||
MAX_QUERY_LIMIT = 2000
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CryptocompareCoinlist:
|
||||
"""Cryptocompare coinlist.
|
||||
@@ -83,4 +86,16 @@ def get_histo(period, fsym, tsym, e, limit=None, toTs=None):
|
||||
if toTs is not None:
|
||||
params["toTs"] = toTs
|
||||
|
||||
return requests.get(url, params=params).json()
|
||||
r = requests.get(url, params=params)
|
||||
|
||||
# Errors and warnings
|
||||
r.raise_for_status()
|
||||
|
||||
# The api raises a 200 for a warning
|
||||
rjson = r.json()
|
||||
if len(rjson['Data']) == 0:
|
||||
logger.warning(rjson["Message"])
|
||||
elif rjson.get("Message", None):
|
||||
logger.info(rjson["Message"])
|
||||
|
||||
return rjson
|
||||
|
||||
Reference in New Issue
Block a user