-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_balance.py
34 lines (31 loc) · 972 Bytes
/
get_balance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from etherscan.accounts import Account
import json
import sys
TOKEN = sys.argv[1]
balances = {}
if os.path.exists('balances.json'):
with open('balances.json') as fd:
balances = json.load(fd)
count = 0
nb_contracts = 47518
with open('all_contract.csv') as fp:
line = fp.readline()
while line:
address = line.split(',')[0]
count += 1
if address == 'address' or address in balances:
line = fp.readline()
continue
if count % 20 == 0:
with open('balances.json', 'w') as fd:
json.dump(balances, fd)
print(count, '/', nb_contracts, round(count * 100 / nb_contracts, 2), '%')
try:
api = Account(address=address, api_key=TOKEN)
balance = int(api.get_balance())
balances[address] = balance
except Exception as identifier:
print(identifier)
continue
line = fp.readline()