Created
July 13, 2022 17:31
-
-
Save NeilHanlon/182f567a27d94d47519956c17f1caa23 to your computer and use it in GitHub Desktop.
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 requests | |
import typing as t | |
repos = { | |
"alpine": None, | |
"debian": None, | |
"ubuntu": None, | |
"centos": None, | |
"fedora": None, | |
"archlinux": ["archlinux"], | |
"opensuse": ["leap"], | |
"rockylinux": ["rockylinux"], | |
"almalinux": ["almalinux"] | |
} | |
def request(namespace: str, image: str): | |
urltpl = f"https://hub.docker.com/v2/repositories/{namespace}/{image}" | |
r = requests.get(urltpl) | |
if r.status_code == 200: | |
return r.json() | |
raise Exception(f"{r.status_code}: {namespace}/{image}") | |
def get_count(namespace: str, image: str): | |
return request(namespace, image)["pull_count"] | |
def count_pulls(os: str, tags: t.Union[t.List[str], None]) -> t.Tuple[int,int]: | |
# get the count of the Official library namespace images | |
library = get_count("library", os) | |
nonlibrary = 0 | |
if tags: | |
# if tags is not None, look inside the {os}/{t for t in tags} to count, too | |
for t in tags: | |
nonlibrary += get_count(os, t) | |
return library, nonlibrary, library+nonlibrary | |
totals = {} | |
for os, tags in repos.items(): | |
totals[os] = count_pulls(os, tags) | |
for os, (library, nonlibrary, total) in sorted(totals.items(), reverse=True, key=lambda k: k[1][2]): | |
print(f"{os : >20} {library:>20,} {nonlibrary:>20,} {total:>20,}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment