diff --git a/etherscan/accounts.py b/etherscan/accounts.py index d9e3264..2bf7177 100644 --- a/etherscan/accounts.py +++ b/etherscan/accounts.py @@ -4,7 +4,7 @@ class Account(Client): PAGE_NUM_PATTERN = re.compile( - '[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0') + r'[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0') def __init__(self, address=Client.dao_address, api_key='YourApiKeyToken'): Client.__init__(self, address=address, api_key=api_key) diff --git a/etherscan/client.ropsten.py b/etherscan/client.ropsten.py index 5e86661..a4fbdcc 100644 --- a/etherscan/client.ropsten.py +++ b/etherscan/client.ropsten.py @@ -30,12 +30,12 @@ class BadRequest(ClientException): """Invalid request passed""" -# Assume user puts his API key in the api_key.json file under variable name "key" +# API key must be in the api_key.json file under variable name "key" class Client(object): dao_address = '0xbb9bc244d798123fde783fcc1c72d3bb8c189413' # Constants - PREFIX = 'https://api-ropsten.etherscan.io/api?' # TESTNET + PREFIX = 'https://api-ropsten.etherscan.io/api?' # TESTNET MODULE = 'module=' ACTION = '&action=' CONTRACT_ADDRESS = '&contractaddress=' @@ -101,7 +101,8 @@ def __init__(self, address, api_key=''): self.url_dict[self.ADDRESS] = address def build_url(self): - self.url = self.PREFIX + ''.join([param + val if val else '' for param, val in self.url_dict.items()]) + self.url = self.PREFIX + ''.join( + [parm + val if val else '' for parm, val in self.url_dict.items()]) def connect(self): # TODO: deal with "unknown exception" error @@ -119,14 +120,15 @@ def connect(self): return data else: raise EmptyResponse(data.get('message', 'no message')) - raise BadRequest("Problem with connection, status code: %s" % req.status_code) + raise BadRequest( + f"Problem with connection, status code: {req.status_code}") def check_and_get_api(self): if self.url_dict[self.API_KEY]: # Check if api_key is empty string pass else: - self.url_dict[self.API_KEY] = input('Please type your EtherScan.io API key: ') + self.url_dict[self.API_KEY] = input( + 'Please type your EtherScan.io API key: ') def check_keys_api(self, data): - return all (k in data for k in ('jsonrpc', 'id', 'result')) - \ No newline at end of file + return all(k in data for k in ('jsonrpc', 'id', 'result')) diff --git a/etherscan/contracts.py b/etherscan/contracts.py index df02a8a..9b07d62 100644 --- a/etherscan/contracts.py +++ b/etherscan/contracts.py @@ -16,4 +16,4 @@ def get_sourcecode(self): self.url_dict[self.ACTION] = 'getsourcecode' self.build_url() req = self.connect() - return req['result'] \ No newline at end of file + return req['result'] diff --git a/tests/test_accounts.py b/tests/test_accounts.py index 138f738..12a17a6 100644 --- a/tests/test_accounts.py +++ b/tests/test_accounts.py @@ -2,18 +2,25 @@ from etherscan.accounts import Account -SINGLE_BALANCE = '40807168566070000000000' +SINGLE_BALANCE = '40807178566070000000000' SINGLE_ACCOUNT = '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a' -MULTI_ACCOUNT = ['0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', - '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'] +MULTI_ACCOUNT = [ + '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', + '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', +] MULTI_BALANCE = [ - {'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', - 'balance': '40807168566070000000000'}, - {'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', - 'balance': '40807168566070000000000'} + { + 'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', + 'balance': '40807178566070000000000' + }, + { + 'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', + 'balance': '40807178566070000000000', + } ] API_KEY = 'YourAPIkey' + class AccountsTestCase(unittest.TestCase): def test_get_balance(self): @@ -22,4 +29,4 @@ def test_get_balance(self): def test_get_balance_multi(self): api = Account(address=MULTI_ACCOUNT, api_key=API_KEY) - self.assertEqual(api.get_balance_multiple(), MULTI_BALANCE) \ No newline at end of file + self.assertEqual(api.get_balance_multiple(), MULTI_BALANCE)