GitHubFileDownloader.create_url

classmethod GitHubFileDownloader.create_url(url)[source]

Creates a URL compatible with GitHub’s REST API from the given URL.

Handles blob or tree paths.

Parameters:

url (str) – URL.

Returns:

Tuple containing the URL of the GitHub repository and the pathname for downloading a file.

Return type:

tuple

Examples:

>>> from pyhelpers.ops import GitHubFileDownloader
>>> main_page = 'https://github.com/mikeqfu'
>>> output_dir = "tests/temp"
>>> url = f'{main_page}/pyhelpers/blob/master/tests/data/dat.csv'
>>> downloader = GitHubFileDownloader(url, output_dir=output_dir)
>>> api_url, download_path = downloader.create_url(url)
>>> api_url
'https://api.github.com/repos/mikeqfu/pyhelpers/contents/tests/data/dat.csv?ref=mas...
>>> download_path
'tests/data/dat.csv'
>>> url = f'{main_page}/smart-home-product-reviews-analysis/tree/master/demos'
>>> downloader = GitHubFileDownloader(url, output_dir=output_dir)
>>> api_url, download_path = downloader.create_url(url)
>>> api_url
'https://api.github.com/repos/mikeqfu/smart-home-product-reviews-analysis/contents/...
>>> download_path
'demos'