Github API:如何按星数对公共存储库进行排序? [英] Github API: How to sort public repositories by count of stars?
问题描述
我正在寻找github上的api,该API可以给我一些用于存储库的星号
I am looking for api on github that could give me a count of stars for repositories
我了解/repositories
,它们为我提供了公共存储库,但我不知道如何获取存储库的星级.
I know about /repositories
which give me public repositories but I don't know how to get count of stars of repository.
有人可以帮忙吗?
推荐答案
从/存储库
中获取所有公共存储库.作为响应,您将获得所有者的名称以及存储库名称,然后在每个存储库上使用 Get
.对于每个存储库的响应,字段 stargazers_count
将为您提供每个存储库拥有的星数.
From /repositories
get all the public repositories. In response you would get name of the owner and also repository name, then use Get
on each of those repositories. In the response of for each of those repositories, field stargazers_count
will give you number of stars each repository has.
一些示例python代码:
Some sample python code:
import requests
public_repos = requests.get('https://api.github.com/repositories').json()
for repo in public_repos:
repo_name = repo['name']
owner = repo['owner']['login']
repo_info = requests.get('https://api.github.com/repos/'+owner+'/'+repo_name)
stars = repo_info.json()['stargazers_count']
print(repo_name, stars)
输出为:
grit 1874
merb-core 401
rubinius 2176
god 1592
jsawesome 12
看看/repositories 和
这篇关于Github API:如何按星数对公共存储库进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!