Skip to content

Instantly share code, notes, and snippets.

@calvang
Created December 25, 2020 22:00
Show Gist options
  • Save calvang/c36ae007d899b62ac03766199a19ed5c to your computer and use it in GitHub Desktop.
Save calvang/c36ae007d899b62ac03766199a19ed5c to your computer and use it in GitHub Desktop.
CLI utility to detect a specific binary from the latest Github release given a repository and a list of keywords. Returns either the full url to retrieve the binary or the filename of the binary.
import sys
import requests
if len(sys.argv) < 4:
print(
"""Invalid arguments.
Format: python3 latest_github_release.py <repo> [OPTIONS] <keywords>.
Type 'help' in options for more.""")
exit(1)
if sys.argv[2] == "help":
print(
"""Format: python3 latest_github_release.py <repo> [OPTIONS] <keywords>.
help: display help menu
url: output file url
name: output file name
**Note that there can be any number of keywords**""")
repo = sys.argv[1]
keywd_strings = sys.argv[3:]
response = requests.get(f"https://api.github.com/repos/{repo}/releases/latest")
content = response.json()
for asset in content["assets"]:
name = asset["name"]
if all(keywd in name for keywd in keywd_strings):
if sys.argv[2] == "url":
print(asset["browser_download_url"])
else:
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment