Created
December 30, 2021 16:41
-
-
Save FloPinguin/3db2c19f7b08157860c8cece7d6036d8 to your computer and use it in GitHub Desktop.
Prints the total size of all items from specified internet archive accounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment