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


当前回答

这里是一个使用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))

其他回答

有一个很好的Chrome扩展,完全做你想要的: GitHub发布下载

11年后…… 下面是一个小的python3代码片段,用于检索最近100个发行版资产的下载计数:

import requests

owner = "twbs"
repo = "bootstrap"
h = {"Accept": "application/vnd.github.v3+json"}
u = f"https://api.github.com/repos/{owner}/{repo}/releases?per_page=100"
r = requests.get(u, headers=h).json()
r.reverse() # older tags first
for rel in r:
  if rel['assets']:
    tag = rel['tag_name']
    dls = rel['assets'][0]['download_count']
    pub = rel['published_at']
    print(f"Pub: {pub} | Tag: {tag} | Dls: {dls} ")

Pub: 2013-07-18T00:03:17Z | Tag: v1.2.0 | Dls: 1193 
Pub: 2013-08-19T21:20:59Z | Tag: v3.0.0 | Dls: 387786 
Pub: 2013-10-30T17:07:16Z | Tag: v3.0.1 | Dls: 102278 
Pub: 2013-11-06T21:58:55Z | Tag: v3.0.2 | Dls: 381136 
...
Pub: 2020-12-07T16:24:37Z | Tag: v5.0.0-beta1 | Dls: 93943 

Demo

这里是一个使用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))

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

基于VonC和Michele Milidoni的答案,我创建了这个bookmarklet,它显示了github托管发布的二进制文件的下载统计数据。

注意:由于浏览器与内容安全策略实现相关的问题,bookmarklet可能会暂时违反一些CSP指令,并且在启用CSP时在github上运行时基本可能无法正常工作。

虽然这是非常不鼓励的,你可以禁用CSP在Firefox作为 临时的解决方案。打开about:config并设置security.csp.enable 为假。