GitHubFileDownloader.create_url

static GitHubFileDownloader.create_url(url)[source]

From the given url, produce a URL that is compatible with GitHub’s REST API.

It can handle blob or tree paths.

Parameters:

url (str) – URL

Returns:

URL of a GitHub repository and pathname for downloading file

Return type:

tuple

Examples:

>>> from pyhelpers.ops import GitHubFileDownloader

>>> test_output_dir = "tests/temp"

>>> test_url = "https://github.com/mikeqfu/pyhelpers/blob/master/tests/data/dat.csv"
>>> downloader = GitHubFileDownloader(test_url, output_dir=test_output_dir)
>>> test_api_url, test_download_path = downloader.create_url(test_url)
>>> test_api_url
'https://api.github.com/repos/mikeqfu/pyhelpers/contents/tests/data/dat.csv?ref=master'
>>> test_download_path
'tests/data/dat.csv'

>>> test_url = "https://github.com/xyluo25/openNetwork/blob/main/docs"
>>> downloader = GitHubFileDownloader(test_url, output_dir=test_output_dir)
>>> test_api_url, test_download_path = downloader.create_url(test_url)
>>> test_api_url
'https://api.github.com/repos/xyluo25/openNetwork/contents/docs?ref=main'
>>> test_download_path
'docs'