Created
June 3, 2018 06:45
-
-
Save dannyvoid/81c56d051a689bbfd148950102ff7708 to your computer and use it in GitHub Desktop.
Function to download latest asset from a Github Repo
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 urllib.request | |
import os | |
def update_from_github(github_username, github_repo, github_asset, local_directory): | |
github_repo_url = 'https://github.com/{}/{}/releases/latest'.format(github_username, github_repo) | |
github_asset_url = requests.get(github_repo_url).url.replace('tag', 'download') + '/' + github_asset | |
destination = os.path.join(local_directory, github_asset) | |
try: | |
print('Deleting current {}'.format(github_asset)) | |
os.remove(destination) | |
print('Done!') | |
except OSError: | |
print('{} does not exist!'.format(github_asset)) | |
pass | |
try: | |
print('Downloading latest {}'.format(github_asset)) | |
urllib.request.urlretrieve(github_asset_url, destination) | |
print('Done!') | |
except OSError: | |
print('Could not download {} for some reason!'.format(github_asset)) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment