-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
root
committed
Jun 1, 2024
1 parent
56710c7
commit 2069596
Showing
17 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Simple script that downloads github files | ||
""" | ||
|
||
import os | ||
import requests | ||
import base64 | ||
import sys | ||
import time | ||
|
||
try: | ||
from FreewayTools.colors import cprint, iprint, wprint, cinput, ColorCodes | ||
|
||
except ModuleNotFoundError: | ||
from colors import cprint, iprint, wprint, cinput, ColorCodes | ||
|
||
def download_folder_from_github(owner, repo, path, local_dir, token=None): | ||
if not os.path.exists(local_dir): | ||
os.makedirs(local_dir) | ||
|
||
url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}" | ||
headers = { | ||
"Accept": "application/vnd.github.v3+json", | ||
} | ||
if token: | ||
headers["Authorization"] = f"Bearer {token}" | ||
|
||
response = requests.get(url, headers=headers) | ||
if response.status_code == 200: | ||
files = response.json() | ||
for file in files: | ||
if file['type'] == 'file': | ||
download_url = file['download_url'] | ||
file_response = requests.get(download_url) | ||
local_file_path = os.path.join(local_dir, file['name']) | ||
with open(local_file_path, 'wb') as local_file: | ||
local_file.write(file_response.content) | ||
cprint(f"Downloaded: {file['name']}") | ||
else: | ||
# If there are subdirectories, call the function recursively | ||
download_folder_from_github(owner, repo, file['path'], os.path.join(local_dir, file['name']), token) | ||
else: | ||
wprint(f"Failed to get contents of directory: {response.status_code}") |
This file contains 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
This file contains 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