Größe von Internet Archive (archive.org) Accounts herausfinden, mit Python

import subprocess
import io
import math
import json

accounts = ["<Mail address of the IA account>"]

def convert_size(size_bytes):
    if size_bytes == 0:
        return "0B"
    size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
    i = int(math.floor(math.log(size_bytes, 1024)))
    p = math.pow(1024, i)
    s = round(size_bytes / p, 2)
    return "%s %s" % (str(s).replace(".", ","), size_name[i])

all_items = 0
all_total_size = 0

for account in accounts:
    items = 0
    total_size = 0

    out = subprocess.check_output("ia search -f item_size " + account, shell=True, stderr=subprocess.STDOUT)
    jsons = io.StringIO(out.decode("utf-8"))
    for j in jsons:
        items = items + 1
        all_items = all_items + 1
        total_size = total_size + json.loads(j)['item_size']
        all_total_size = all_total_size + json.loads(j)['item_size']

    print(account + ": " + str(items) + " items, " + convert_size(total_size))

print("= " + str(all_items) + " items, " + convert_size(all_total_size))