import argparse import requests def getArtifactUrl(runUrl): artifactUrl = None r = requests.get(runUrl) if r.status_code == 200: print(r.json()['artifacts'][0]) artifactUrl = r.json()['artifacts'][0]["archive_download_url"] return artifactUrl def getArtifact(artifactUrl, gh_tokenfile, outputfile): gh_token = None with open(gh_tokenfile, 'r') as f: gh_token = f.read() headers = {'Authorization': f'token {gh_token}'} r = requests.get(artifactUrl, headers=headers) if r.status_code == 200: with open(outputfile, mode="wb") as file: file.write(r.content) else: print(r.status_code) def main(): parser = argparse.ArgumentParser(description='Download artifact from github') parser.add_argument('url', help='url for the artifact building run') parser.add_argument('gh_tokenfile', help='authentication token') parser.add_argument('outputfile', help='where to store downloaded file') args = parser.parse_args() artifact_url = getArtifactUrl(args.url) print(artifact_url) getArtifact(artifact_url, args.gh_tokenfile, args.outputfile) if __name__ == '__main__': main()