github-folder-downloader 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of github-folder-downloader might be problematic. Click here for more details.

@@ -0,0 +1,4 @@
1
+ from .downloader import download_from_github
2
+
3
+ __version__ = "0.1.0"
4
+ __all__ = ["download_from_github"]
@@ -0,0 +1,38 @@
1
+ import argparse
2
+ import sys
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser(
6
+ description="Download files or folders from GitHub repositories"
7
+ )
8
+ parser.add_argument(
9
+ "url",
10
+ nargs="?", # Make the URL optional
11
+ help="GitHub URL to download (e.g., https://github.com/user/repo/tree/branch/path)"
12
+ )
13
+ parser.add_argument(
14
+ "-o", "--output",
15
+ default="./downloaded_files",
16
+ help="Output directory (default: ./downloaded_files)"
17
+ )
18
+
19
+ args = parser.parse_args()
20
+
21
+ # If no URL provided, show usage examples and prompt for input
22
+ if not args.url:
23
+ print("\nUsage examples:")
24
+ print(" github-download https://github.com/user/repo/blob/master/file.pdf")
25
+ print(" github-download https://github.com/user/repo/tree/master/docs")
26
+ print(" github-download -o ./custom/path https://github.com/user/repo/tree/master\n")
27
+
28
+ args.url = input("Enter the GitHub URL to download: ").strip()
29
+
30
+ if not args.url:
31
+ parser.print_help()
32
+ sys.exit(1)
33
+
34
+ from .downloader import download_from_github
35
+ download_from_github(args.url, args.output)
36
+
37
+ if __name__ == "__main__":
38
+ main()
@@ -0,0 +1,65 @@
1
+ import requests
2
+ import os
3
+ import re
4
+ from typing import Tuple
5
+
6
+ def download_file(url: str, dest_folder: str) -> None:
7
+ """Download a single file from GitHub and save it to the destination folder."""
8
+ os.makedirs(dest_folder, exist_ok=True)
9
+ filename = os.path.join(dest_folder, url.split('/')[-1])
10
+ response = requests.get(url, stream=True)
11
+ if response.status_code == 200:
12
+ with open(filename, 'wb') as file:
13
+ for chunk in response.iter_content(1024):
14
+ file.write(chunk)
15
+ print(f"Downloaded: {filename}")
16
+ else:
17
+ print(f"Failed to download: {url}")
18
+
19
+ def download_content(repo: str, path: str, branch: str, dest_folder: str) -> None:
20
+ """
21
+ Recursively download content from a specified GitHub repository path.
22
+ Handles both files and folders within the path.
23
+ """
24
+ api_url = f"https://api.github.com/repos/{repo}/contents/{path}?ref={branch}"
25
+ headers = {'Accept': 'application/vnd.github.v3+json'}
26
+ response = requests.get(api_url, headers=headers)
27
+
28
+ if response.status_code == 200:
29
+ content = response.json()
30
+ if isinstance(content, dict): # Single file
31
+ download_file(content['download_url'], dest_folder)
32
+ else: # Directory
33
+ for item in content:
34
+ if item['type'] == 'file':
35
+ download_file(item['download_url'], dest_folder)
36
+ elif item['type'] == 'dir':
37
+ download_content(repo, item['path'], branch, os.path.join(dest_folder, item['name']))
38
+ else:
39
+ print(f"Failed to retrieve contents at: {api_url}")
40
+
41
+ def parse_github_url(url: str) -> Tuple[str, str, str]:
42
+ """Extract the repository name, branch, and path from a GitHub URL."""
43
+ match = re.match(r"https://github\.com/([^/]+)/([^/]+)/(tree|blob)/([^/]+)(?:/(.+))?", url)
44
+ if match:
45
+ repo = f"{match.group(1)}/{match.group(2)}"
46
+ branch = match.group(4)
47
+ path = match.group(5) if match.group(5) else ""
48
+ return repo, branch, path
49
+ else:
50
+ raise ValueError("Invalid GitHub URL format. Please ensure it follows the pattern: https://github.com/username/repo/(tree|blob)/branch[/path]")
51
+
52
+ def download_from_github(url: str, dest_folder: str = "./downloaded_files") -> None:
53
+ """
54
+ Main function to download content from GitHub.
55
+
56
+ Args:
57
+ url (str): GitHub URL to download from
58
+ dest_folder (str): Destination folder for downloads
59
+ """
60
+ try:
61
+ repo, branch, path = parse_github_url(url)
62
+ print(f"Downloading content from {repo}/{path} on branch {branch}...")
63
+ download_content(repo, path, branch, dest_folder)
64
+ except ValueError as e:
65
+ print(e)
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.1
2
+ Name: github-folder-downloader
3
+ Version: 0.1.0
4
+ Summary: A tool to download files and folders from GitHub repositories
5
+ Home-page: https://github.com/yourusername/github-folder-downloader
6
+ Author: Your Name
7
+ Author-email: your.email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: requests >=2.25.0
14
+
15
+ # GitHub Folder Downloader
16
+
17
+ A simple Python package to download files and folders from GitHub repositories.
18
+
19
+ ## Installation
@@ -0,0 +1,8 @@
1
+ github_downloader/__init__.py,sha256=FdH0bEtGOgSoDDdzYKJBEC_oGKZlmoyP56TdqSrXeRQ,103
2
+ github_downloader/cli.py,sha256=v6hgLZLAugV1nOi3FtQAMCSUcWalG25CWe3GT9Akh5I,1232
3
+ github_downloader/downloader.py,sha256=1YPidmDZ9vU5sKkzixvQFGVpPX_pcADw2iupk9jI_88,2710
4
+ github_folder_downloader-0.1.0.dist-info/METADATA,sha256=UnylYa9xHs4KHIgtuTJXU8Rp-D2YUIiUG-v6QYTT2HE,631
5
+ github_folder_downloader-0.1.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
6
+ github_folder_downloader-0.1.0.dist-info/entry_points.txt,sha256=te_58U4jaFJ1XKfINbz3iqaSlFbS2ruIRbcNzPgSKvs,63
7
+ github_folder_downloader-0.1.0.dist-info/top_level.txt,sha256=jI6eLrtv-oEtxZBwd4OuZUGu-Yj-m0J5LvdIWTYNHW8,18
8
+ github_folder_downloader-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.3.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ github-download = github_downloader.cli:main
@@ -0,0 +1 @@
1
+ github_downloader