有没有办法 bulk/batch 根据搜索结果从 Github 下载所有存储库?
Is there a way to bulk/batch download all repos from Github based on a search result?
我 运行 在 Guthub 上搜索,我得到了 881 个回购。 Blazor 和 C# 回购。
https://github.com/search?l=C%23&q=blazor&type=Repositories
有没有一种方法可以轻松下载所有这些存储库而不是一个一个地下载?
是的,您的查询可以 运行 通过 github 搜索 api:
这为您提供了一页 100 个存储库。您可以遍历所有页面,提取 ssh_url(或 http,如果您愿意),并将结果写入文件:
# cheating knowing we currently have 9 pages
for i in {1..9}
do
curl "https://api.github.com/search/repositories?q=blazor+language:C%23&per_page=100&page=$i" \
| jq -r '.items[].ssh_url' >> urls.txt
done
cat urls.txt | xargs -P8 -L1 git clone
您可以优化以从响应中提取页数 headers。
参考文献:
- https://developer.github.com/v3/search/
- Parsing JSON with Unix tools
- How to apply shell command to each line of a command output?
- Running programs in parallel using xargs
类似问题:
我 运行 在 Guthub 上搜索,我得到了 881 个回购。 Blazor 和 C# 回购。 https://github.com/search?l=C%23&q=blazor&type=Repositories
有没有一种方法可以轻松下载所有这些存储库而不是一个一个地下载?
是的,您的查询可以 运行 通过 github 搜索 api:
这为您提供了一页 100 个存储库。您可以遍历所有页面,提取 ssh_url(或 http,如果您愿意),并将结果写入文件:
# cheating knowing we currently have 9 pages
for i in {1..9}
do
curl "https://api.github.com/search/repositories?q=blazor+language:C%23&per_page=100&page=$i" \
| jq -r '.items[].ssh_url' >> urls.txt
done
cat urls.txt | xargs -P8 -L1 git clone
您可以优化以从响应中提取页数 headers。
参考文献:
- https://developer.github.com/v3/search/
- Parsing JSON with Unix tools
- How to apply shell command to each line of a command output?
- Running programs in parallel using xargs
类似问题: