Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
#4: Switches to f-Strings instead of .format()
Browse files Browse the repository at this point in the history
  • Loading branch information
tlex committed Feb 9, 2020
1 parent 94f2288 commit 48b98c0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/etherscan-exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def configure_logging():
)
LOG.addHandler(GELF)
gelf_enabled = True
LOG.info('Initialized logging with GELF enabled: {}'.format(gelf_enabled))
LOG.info(f'Initialized logging with GELF enabled: {gelf_enabled}')


class EtherscanCollector:
Expand Down Expand Up @@ -77,18 +77,18 @@ def get_tokens(self):
decimals = 18
if token.get('decimals', -1) >= 0:
decimals = int(token['decimals'])
LOG.debug('{} decimals for {}'.format(decimals, token['short']))
LOG.debug(f"{decimals} decimals for {token['short']}")
try:
req = requests.get(self.settings['url'], params=request_data).json()
except (
requests.exceptions.ConnectionError,
requests.exceptions.ReadTimeout,
) as error:
LOG.exception('Exception caught: {}'.format(error))
LOG.exception(f'Exception caught: {error}')
req = {}
if req.get('result') and int(req['result']) > 0:
self.tokens.update({
'{}-{}'.format(account, token['short']): {
f"{account}-{token['short']}": {
'account': account,
'name': token['name'],
'name_short': token['short'],
Expand All @@ -97,7 +97,7 @@ def get_tokens(self):
}
})

LOG.debug('Tokens: {}'.format(self.tokens))
LOG.debug(f'Tokens: {self.tokens}')

def get_balances(self):
""" Gets the current balance for an account """
Expand All @@ -108,21 +108,21 @@ def get_balances(self):
'tag': 'latest',
'apikey': self.settings['api_key'],
}
LOG.debug('Request data: {}'.format(request_data))
LOG.debug(f'Request data: {request_data}')
try:
req = requests.get(self.settings['url'], params=request_data).json()
except (
requests.exceptions.ConnectionError,
requests.exceptions.ReadTimeout,
) as error:
LOG.exception('Exception caught: {}'.format(error))
LOG.exception(f'Exception caught: {error}')
req = {}
if req.get('message') == 'OK' and req.get('result'):
for result in req.get('result'):
self.accounts.update({
result['account']: float(result['balance'])/(1000000000000000000)
})
LOG.debug('Accounts: {}'.format(self.accounts))
LOG.debug(f'Accounts: {self.accounts}')

def describe(self):
""" Just a needed method, so that collect() isn't called at startup """
Expand Down Expand Up @@ -166,9 +166,9 @@ def collect(self):

if __name__ == '__main__':
configure_logging()
PORT = int(os.environ.get('PORT', 9308))
LOG.info("Starting {} {} on port {}".format(FILENAME, version, PORT))
port = int(os.environ.get('PORT', 9308))
LOG.info(f'Starting {__package__} {version} on port {port}')
REGISTRY.register(EtherscanCollector())
start_http_server(PORT)
start_http_server(port)
while True:
time.sleep(1)

0 comments on commit 48b98c0

Please # to comment.