Last active
September 22, 2022 06:29
-
-
Save ddelange/e4fb438f2f724413f45c4bece46aacfa to your computer and use it in GitHub Desktop.
Create a PIP_FIND_LINKS page containing all release assets
This file contains 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
from itertools import count | |
from os import environ | |
import dominate | |
import requests | |
GITHUB_API_URL = environ["GITHUB_API_URL"] | |
GITHUB_REPOSITORY = environ["GITHUB_REPOSITORY"] | |
links = {} | |
for i in count(1): | |
resp = requests.get( | |
f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/releases", | |
params={"page": i, "per_page": 100}, | |
) | |
resp.raise_for_status() | |
payload = resp.json() | |
if not payload: | |
break | |
for release in payload: | |
for asset in release["assets"]: | |
if asset["name"] not in links: | |
# keep the first one encountered (latest release) | |
links[asset["name"]] = asset["browser_download_url"] | |
doc = dominate.document(title=GITHUB_REPOSITORY) | |
with doc: | |
with dominate.tags.div(): | |
for name, link in sorted(links.items()): | |
dominate.tags.a(name, href=link) | |
dominate.tags.br() | |
print(doc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment