Upload a GitHub account to R

I am trying to get the number of public repo downloads using the GitHub API and R v3.1.2. Using the public repo samples from Google, I have the following:

library(jsonlite) library(httr) url <- "https://api.github.com/repos/googlesamples/google-services/downloads" response <- GET(url) json <- content(response, "text") json <- fromJSON(json) print(json) 

However, I noticed that json returns an empty list. Is it because there are no releases in this public repo? The goal is to determine how many times this repo has been downloaded by the public - or any other public repo, for that matter. Is it possible?

+5
source share
2 answers

Old Github boot values are deprecated and seem to no longer work. You can get download counts from releases, but this requires a bit of manipulation:

 library(jsonlite) library(httr) url <- "https://api.github.com/repos/allenluce/mmap-object/releases" response <- GET(url) json <- content(response, "text") json <- fromJSON(json) print(Reduce("+", lapply(json$assets, function(x) sum(x$download_count)))) 

There are some caveats:

  • There must be releases in the repo.
  • There must be files in releases
  • There is no API to get the number of people who cloned your repo.

Github allows you to count the number of released files that have been downloaded, but more on that. The google-services repo you are using as an example has neither releases nor files!

+4
source

The API mentioned in Get One Release :

 GET /repos/:owner/:repo/releases/:id 

As commented, you need to apply it to the repo release.
An example is the python gist ( Philip Hansen - Hanse00 ), which retrieves download_count .
(not in R, but to show how the URL /repos/:owner/:repo/releases/:id )

Extract:

 #Iterate through every tag search_point = 0 while formatted_string.find("tag_name", search_point) != -1: #Find where in the string the tag and download texts are find_point = formatted_string.find("tag_name", search_point) download_point = formatted_string.find("download_count", find_point) 

Here is an even smaller Brad Chapman chapmanb script using sigmavirus24/github3.py (Python library for interacting with GitHub APIv3):

 #!/usr/bin/env python """Get download stats for releases from GitHub. Needs development version of github3. pip install github3 pip install git+https://github.com/sigmavirus24/github3.py.git """ import github3 repo = github3.repository("chapmanb", "bcbio.variation") for release in repo.iter_releases(): for asset in release.iter_assets(): print release.name, asset.name, asset.download_count 

(You have many more examples )

+1
source

Source: https://habr.com/ru/post/1243807/


All Articles