在Github中,是否有一种方法可以让我看到回购的下载数量?


当前回答

我用javascript写了一个小的web应用程序,用于显示Github上任何项目可用版本中所有资产的下载数量。您可以在这里试用该应用程序:http://somsubhra.github.io/github-release-stats/

其他回答

以前,在Github中有两种下载代码的方法:克隆或作为zip下载一个.git repo,或上传一个文件(例如,二进制文件)供以后下载。

当下载一个回购(克隆或下载压缩),Github不计算下载数量的技术限制。克隆存储库是一个只读操作。不需要身份验证。这个操作可以通过许多协议来完成,包括HTTPS, web页面在浏览器中显示回购时使用的协议。很难数出来。

参见:http://git-scm.com/book/en/Git-on-the-Server-The-Protocols

最近,Github弃用了下载功能。这是因为他们明白Github专注于构建软件,而不是分发二进制文件。

参见:https://github.com/blog/1302-goodbye-uploads

这里是一个使用pip install PyGithub包的python解决方案

from github import Github
g = Github("youroauth key") #create token from settings page


for repo in g.get_user().get_repos():
    if repo.name == "yourreponame":
        releases = repo.get_releases()
        for i in releases:
            if i.tag_name == "yourtagname":
                for j in i.get_assets():
                    print("{} date: {} download count: {}".format(j.name, j.updated_at, j._download_count.value))

为了更清楚地说明这一点: 对于这个github项目:stant/ mdcsvimportter2015 https://github.com/stant/mdcsvimporter2015 在 https://github.com/stant/mdcsvimporter2015/releases

转到HTTP或https:(注意添加了“api.”和“/repos”) https://api.github.com/repos/stant/mdcsvimporter2015/releases

你会得到这个json输出,你可以搜索"download_count":

    "download_count": 2,
    "created_at": "2015-02-24T18:20:06Z",
    "updated_at": "2015-02-24T18:20:07Z",
    "browser_download_url": "https://github.com/stant/mdcsvimporter2015/releases/download/v18/mdcsvimporter-beta-18.zip"

或者在命令行执行: Wget——no-check-certificate https://api.github.com/repos/stant/mdcsvimporter2015/releases

Github API不再提供所需的信息。看看Stan Towianski的回答中提到的发布页面。正如我们在回答的评论中讨论的那样,Github API只报告他每次发布的三个文件中的一个的下载量。

我已经检查了解决方案,在这个问题的其他一些答案。Vonc的回答体现了Michele Milidoni解决方案的关键部分。我安装了他的gdc脚本,结果如下

# ./gdc stant
mdcsvimporter.mxt: 37 downloads
mdcsvimporter.mxt: 80 downloads
How-to-use-mdcsvimporter-beta-16.zip: 12 downloads

正如您可以清楚地看到的,gdc没有报告tar.gz和zip文件的下载计数。

如果您想在不安装任何东西的情况下进行检查,请尝试Somsubhra在他的回答中提到的安装解决方案的网页。填写“stant”作为Github用户名和“mdcsvimportter2015”作为存储库名称,你会看到如下内容:

Download Info:
mdcsvimporter.mxt(0.20MB) - Downloaded 37 times.
Last updated on 2015-03-26

唉,还是只有一个没有下载tar.gz和zip文件的报告。我仔细检查了Github的API返回的信息,但它没有提供任何地方。目前,API返回的download_count还远远不够完整。

我做了一个web应用程序,以干净的格式显示GitHub发布的统计数据: https://hanadigital.github.io/grev/