GitHubFileDownloader.create_url¶
- static GitHubFileDownloader.create_url(url)[source]¶
Create a URL compatible with GitHub’s REST API from the given URL.
Handles blob or tree paths.
- Parameters:
url (str) – Input 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 >>> output_dir = "tests/temp" >>> url = "https://github.com/mikeqfu/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?... >>> download_path 'tests/data/dat.csv' >>> url = "https://github.com/xyluo25/openNetwork/blob/main/docs" >>> downloader = GitHubFileDownloader(url, output_dir=output_dir) >>> api_url, download_path = downloader.create_url(url) >>> api_url 'https://api.github.com/repos/xyluo25/openNetwork/contents/docs?ref=main' >>> download_path 'docs'