-
-
Save skshetry/94d04f5b505d84ea614834617d647cde to your computer and use it in GitHub Desktop.
Fetch all files matching query provided.
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
import sys | |
from github import Github | |
from pathlib import Path | |
token = Path(".token").read_text().strip() | |
g = Github(token) | |
args = sys.argv | |
if len(args) < 2: | |
raise Exception("Query not provided") | |
query = " ".join(sys.argv[1:]) | |
print(f"Querying with '{query}' for files and downloading ...") | |
for file in g.search_code(query=query): | |
repo_path = Path(file.repository.full_name) | |
file_path = repo_path / file.path | |
file_path.parent.mkdir(parents=True, exist_ok=True) | |
file_path.write_bytes(file.decoded_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pre-requisites:
.token
next to the script.pip install PyGithub
Example Usage:
python fetch_files_from_query.py filename:dvc.yaml
Any other valid Github search query could be provided.