summary = defaultdict(lambda: defaultdict(int))
if not args.summary:
    print(f'Name\tKind\tAddress\tGas\tTransactions\tkgCO2')
for name_kind, address in contracts.items():
    if name_kind == 'Nifty Gateway/multiple':
        if args.ng:
            transactions = etherscan.load_transactions_multiple(
                list_nifty_gateway(args.verbose),
                update=args.noupdate,
                verbose=args.verbose)
        else:
            continue
    else:
        transactions = etherscan.load_transactions(address,
                                                   update=args.noupdate,
                                                   verbose=args.verbose)
    gas = sum_gas(transactions, start_date=start_date, end_date=end_date)
    kgco2 = int(
        ethereum_footprint.sum_kgco2(transactions,
                                     start_date=start_date,
                                     end_date=end_date))
    name, kind = name_kind.split('/')
    summary[name]['gas'] += gas
    summary[name]['transactions'] += len(transactions)
    summary[name]['kgco2'] += kgco2
    if not args.summary:
        if args.commas:
            print(
                f'{name}\t{kind}\t{address}\t{gas:,}\t{len(transactions):,}\t{kgco2:,}'
            )
import json
from collections import defaultdict
from etherscan import Etherscan

with open('data/contracts.json') as f:
    contracts = json.load(f)

grouped = defaultdict(set)
for name_kind, address in contracts.items():
    name, kind = name_kind.split('/')
    grouped[name].update([(kind, address)])

etherscan = Etherscan()

for name, kinds_addresses in sorted(grouped.items()):
    print(f'### {name}\n')
    for kind, address in sorted(kinds_addresses):
        dates = [tx.get_datetime() for tx in etherscan.load_transactions(address)]
        min_date = min(dates).date()
        max_date = max(dates).date()
        print(f'* [{kind}](https://etherscan.io/address/{address}) {min_date} to {max_date}')
    print()