# Path: cryptofolio/api/Blockchain.py
# class Blockchain:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = 'https://blockchain.info/q/addressbalance/' + address
#         try:
#             response = requests.get(req_url)
#             return response.json() / 100000000
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Etherscan.py
# class Etherscan:
#     def __init__(self):
#         self.logger = Logger(__name__)
#         try:
#             self.client = Client()
#         except Exception as e:
#             self.logger.log(e)
# 
#     def getBalance(self, address):
#         try:
#             result = self.client.get_single_balance(address)
#             if result.message == 'OK':
#                 return result.balance / 1000000000000000000
# 
#         except Exception as e:
#             self.logger.log(e)
# 
#         return 0.0
# 
# Path: cryptofolio/api/Chainz.py
# class Chainz:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = ('https://chainz.cryptoid.info/ltc/api.dws'
#                    '?q=getbalance&a=') + address
#         try:
#             response = requests.get(req_url)
#             return response.json()
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Blockchair.py
# class Blockchair:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = ('https://api.blockchair.com/bitcoin-cash'
#                    '/dashboards/address/') + address
#         try:
#             response = requests.get(req_url)
#             return int(response.json()['data'][0]['sum_value_unspent'])/100000000
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Ripple.py
# class Ripple:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = ('https://data.ripple.com'
#                    '/v2/accounts/{}/balances'.format(address,))
#         try:
#             response = requests.get(req_url)
#             xrp_balance = next((item for item in response.json()['balances']
#                                         if item["currency"] == "XRP"), None)
#             return xrp_balance['value']
# 
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Logger.py
# class Logger:
#     def __init__(self, root):
#         self.logger = logging.getLogger(root)
#         self.logger.setLevel(logging.DEBUG)
#         ch = logging.StreamHandler()
#         ch.setLevel(logging.DEBUG)
#         formatter = logging.Formatter(
#             '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         ch.setFormatter(formatter)
#         self.logger.addHandler(ch)
# 
#     def log(self, message):
#         self.logger.debug(message)


from .Blockchain import Blockchain
from .Etherscan import Etherscan
from .Chainz import Chainz
from .Blockchair import Blockchair
from .Ripple import Ripple
from .Logger import Logger
from time import sleep


class BalanceFromAddress:
    def __init__(self):
        self.logger = Logger(__name__)
        self.handlers = {
            'BTC': Blockchain(),
            'ETH': Etherscan(),
            'LTC': Chainz(),
            'BCH': Blockchair(),
            'XRP': Ripple()

# Path: cryptofolio/api/Blockchain.py
# class Blockchain:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = 'https://blockchain.info/q/addressbalance/' + address
#         try:
#             response = requests.get(req_url)
#             return response.json() / 100000000
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Etherscan.py
# class Etherscan:
#     def __init__(self):
#         self.logger = Logger(__name__)
#         try:
#             self.client = Client()
#         except Exception as e:
#             self.logger.log(e)
# 
#     def getBalance(self, address):
#         try:
#             result = self.client.get_single_balance(address)
#             if result.message == 'OK':
#                 return result.balance / 1000000000000000000
# 
#         except Exception as e:
#             self.logger.log(e)
# 
#         return 0.0
# 
# Path: cryptofolio/api/Chainz.py
# class Chainz:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = ('https://chainz.cryptoid.info/ltc/api.dws'
#                    '?q=getbalance&a=') + address
#         try:
#             response = requests.get(req_url)
#             return response.json()
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Blockchair.py
# class Blockchair:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = ('https://api.blockchair.com/bitcoin-cash'
#                    '/dashboards/address/') + address
#         try:
#             response = requests.get(req_url)
#             return int(response.json()['data'][0]['sum_value_unspent'])/100000000
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Ripple.py
# class Ripple:
#     def __init__(self):
#         self.logger = Logger(__name__)
# 
#     def getBalance(self, address):
#         req_url = ('https://data.ripple.com'
#                    '/v2/accounts/{}/balances'.format(address,))
#         try:
#             response = requests.get(req_url)
#             xrp_balance = next((item for item in response.json()['balances']
#                                         if item["currency"] == "XRP"), None)
#             return xrp_balance['value']
# 
#         except Exception as e:
#             self.logger.log(e)
#         return 0.0
# 
# Path: cryptofolio/api/Logger.py
# class Logger:
#     def __init__(self, root):
#         self.logger = logging.getLogger(root)
#         self.logger.setLevel(logging.DEBUG)
#         ch = logging.StreamHandler()
#         ch.setLevel(logging.DEBUG)
#         formatter = logging.Formatter(
#             '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         ch.setFormatter(formatter)
#         self.logger.addHandler(ch)
# 
#     def log(self, message):
#         self.logger.debug(message)


# Path: cryptofolio/api/BalanceFromAddress.py
from .Blockchain import Blockchain
from .Etherscan import Etherscan
from .Chainz import Chainz
from .Blockchair import Blockchair
from .Ripple import Ripple
from .Logger import Logger
from time import sleep



class BalanceFromAddress:
    def __init__(self):
        self.logger = Logger(__name__)
        self.handlers = {
            'BTC': Blockchain(),
            'ETH': Etherscan(),
            'LTC': Chainz(),
            'BCH': Blockchair(),
            'XRP': Ripple()

        }