Skip to content

Instantly share code, notes, and snippets.

@dougluce
Created March 14, 2016 19:39
Show Gist options
  • Save dougluce/1956acf8d35e42aab3f2 to your computer and use it in GitHub Desktop.
Save dougluce/1956acf8d35e42aab3f2 to your computer and use it in GitHub Desktop.
R script for scraping cloning stats from Github clone graphs.
library(jsonlite)
library(httr)
library(XML)
username <- "allenluce"
repo <- "mmap-object"
password <- "allenluce's password"
# Go to Github
response <- GET ("https://github.com/login")
body <- content(response, "text")
# Pull out the authenticity_token
html <- htmlTreeParse(body, useInternal = TRUE)
txt <- xpathApply(html, "//input[@type='hidden'][@name='authenticity_token']", function(x) c(xmlValue(x), xmlAttrs(x)[["value"]]))
token <- txt[[1]][[2]]
# Log in
response <- POST("https://github.com/session",
body = list(commit="Sign in",
authenticity_token=token,
login=username,
password=password))
# Grab the clone stats
response <- GET(sprintf("https://github.com/%s/%s/graphs/clone-activity-data", username, repo),
add_headers('x-requested-with'="XMLHttpRequest"))
body <- content(response, "text")
counts <- fromJSON(body)
print(counts)
# Total count is counts$summary$total
# Uniques is counts$summary$unique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment