Skip to content

Instantly share code, notes, and snippets.

@christophergandrud
Created October 20, 2014 13:40
Show Gist options
  • Save christophergandrud/b7c82050cc62a3c0208a to your computer and use it in GitHub Desktop.
Save christophergandrud/b7c82050cc62a3c0208a to your computer and use it in GitHub Desktop.
Downloads Counts of GitHub users with more than 100 followers for three major locations
########################################
# Download GitHub users with more than 100 followers for Berlin, Brooklyn,
# and London
# Christopher Gandrud
# 20 October 2014
########################################
library(httr)
library(dplyr)
library(rjson)
# Create locations vector
locations <- c('Berlin', 'Brooklyn', 'London')
# Create empty vector for user counts
user_counts <- vector()
# Loop through the locations and download the user counts
## Note: the %23E turns into a greater than sign >
for (i in locations){
# Download raw data
URL_temp <- paste0('https://api.github.com/search/users?q=location:', i,
'+followers:%3E100')
users <- GET(URL_temp) %>%
content(as = 'text') %>%
fromJSON()
# Extract counts of users that meet criteria for the location
user_counts_temp <- users$total_count
# Add to user_counts vector
user_counts <- c(user_counts, user_counts_temp)
# Sleep R for 5 seconds so you don't overload the API
Sys.sleep(5); message('-')
}
# Combine locations and user counts data
location_counts <- data.frame(locations, user_counts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment