2

Using this option it is possible to collect user history reputation

library(tidyverse)
library(lubridate)
library(RCurl)
library(magrittr)

# 1 Setup ####

userId <- 11786778 # Select user ID


# 2 Download user reputation history ####

user_reputation <- getURLContent(
  paste0(
    'https://',
    '.stackoverflow.com/users/',
    userId,
    '/?tab=reputation&sort=graph'
  ),
  followlocation = TRUE
)

# If the user has any reputation history/changes  
if (!is.na(str_locate(user_reputation, '\\[\\[')[1, 'end'])) {

  user_reputation <- user_reputation %>% str_sub(
    # Extract only relevant parts of user reputation HTML string
    start = str_locate(., 'var rawData = \\[\\[')[1, 'end'] + 1,
    end = str_locate(., '\\]\\];')[1, 'start'] - 1
  ) %>% str_split(
    '\\],\\['
  ) %>% unlist() %>% trimws() %>% as_tibble() %>% separate(
    col = 'value', 
    into = c(
      'YEAR', 'MONTH', 'DAY', 'REP'
    ),
    sep = ','
  ) %>% transmute(
    DATE = paste(
      YEAR, MONTH, DAY, sep = '-'
    ) %>% ymd(),
    USERID = userId,
    REP = REP %>% as.numeric()
  ) %>% filter(
    REP != 0 # Remove zero-reputation days
  )

} else {
  # User does not have any reputation history available
  user_reputation <- NULL

}

From this history option

https://stackoverflow.com/users/11786778/nathalie?tab=reputation

This is a more detail option for history

How is it possible to keep the detailed history for all time? Example of output:

The expected output to run in R

data.frame(score = c(+100, -2, +10), date = c("2019-11-19 14:35:16Z", "2019-11-16 08:39:43Z", "2019-11-01 15:05:57Z"), action = c("assoc", "downvote", "upvote"), reason_title = c("Association Bonus","Find differences in new values", "Argument ngrams not used"), reason_link  = c(NA, "https://stackoverflow.com/questions/58886103/find-differences-in-new-values", "https://stackoverflow.com/questions/58261741/argument-ngrams-not-used"))
Nathalie
  • 1,228
  • 7
  • 20

0 Answers0