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

Commit 48b98c0

Browse files
committed
#4: Switches to f-Strings instead of .format()
1 parent 94f2288 commit 48b98c0

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/etherscan-exporter.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def configure_logging():
3838
)
3939
LOG.addHandler(GELF)
4040
gelf_enabled = True
41-
LOG.info('Initialized logging with GELF enabled: {}'.format(gelf_enabled))
41+
LOG.info(f'Initialized logging with GELF enabled: {gelf_enabled}')
4242

4343

4444
class EtherscanCollector:
@@ -77,18 +77,18 @@ def get_tokens(self):
7777
decimals = 18
7878
if token.get('decimals', -1) >= 0:
7979
decimals = int(token['decimals'])
80-
LOG.debug('{} decimals for {}'.format(decimals, token['short']))
80+
LOG.debug(f"{decimals} decimals for {token['short']}")
8181
try:
8282
req = requests.get(self.settings['url'], params=request_data).json()
8383
except (
8484
requests.exceptions.ConnectionError,
8585
requests.exceptions.ReadTimeout,
8686
) as error:
87-
LOG.exception('Exception caught: {}'.format(error))
87+
LOG.exception(f'Exception caught: {error}')
8888
req = {}
8989
if req.get('result') and int(req['result']) > 0:
9090
self.tokens.update({
91-
'{}-{}'.format(account, token['short']): {
91+
f"{account}-{token['short']}": {
9292
'account': account,
9393
'name': token['name'],
9494
'name_short': token['short'],
@@ -97,7 +97,7 @@ def get_tokens(self):
9797
}
9898
})
9999

100-
LOG.debug('Tokens: {}'.format(self.tokens))
100+
LOG.debug(f'Tokens: {self.tokens}')
101101

102102
def get_balances(self):
103103
""" Gets the current balance for an account """
@@ -108,21 +108,21 @@ def get_balances(self):
108108
'tag': 'latest',
109109
'apikey': self.settings['api_key'],
110110
}
111-
LOG.debug('Request data: {}'.format(request_data))
111+
LOG.debug(f'Request data: {request_data}')
112112
try:
113113
req = requests.get(self.settings['url'], params=request_data).json()
114114
except (
115115
requests.exceptions.ConnectionError,
116116
requests.exceptions.ReadTimeout,
117117
) as error:
118-
LOG.exception('Exception caught: {}'.format(error))
118+
LOG.exception(f'Exception caught: {error}')
119119
req = {}
120120
if req.get('message') == 'OK' and req.get('result'):
121121
for result in req.get('result'):
122122
self.accounts.update({
123123
result['account']: float(result['balance'])/(1000000000000000000)
124124
})
125-
LOG.debug('Accounts: {}'.format(self.accounts))
125+
LOG.debug(f'Accounts: {self.accounts}')
126126

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

167167
if __name__ == '__main__':
168168
configure_logging()
169-
PORT = int(os.environ.get('PORT', 9308))
170-
LOG.info("Starting {} {} on port {}".format(FILENAME, version, PORT))
169+
port = int(os.environ.get('PORT', 9308))
170+
LOG.info(f'Starting {__package__} {version} on port {port}')
171171
REGISTRY.register(EtherscanCollector())
172-
start_http_server(PORT)
172+
start_http_server(port)
173173
while True:
174174
time.sleep(1)

0 commit comments

Comments
 (0)