Skip to content

Instantly share code, notes, and snippets.

@NeilHanlon
Created July 13, 2022 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeilHanlon/6bf7e75fbc9cb8b0e6d1567eee103706 to your computer and use it in GitHub Desktop.
Save NeilHanlon/6bf7e75fbc9cb8b0e6d1567eee103706 to your computer and use it in GitHub Desktop.
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