Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rm(list=ls())
library(jsonlite)
library(dplyr)
setwd('/Users/erikgregorywebb/Documents/Python/venmo')
# function to get transaction data
transaction_data <- function(url) {
raw <- fromJSON(url)$data
temp_1 <- data.frame(payment_id = raw$payment_id,
permalink = raw$permalink,
via = raw$via,
story_id = raw$story_id,
audience = raw$audience,
updated_time = raw$updated_time,
created_time = raw$created_time,
message = raw$message,
type = raw$type,
likes = raw$likes$count)
temp_2 <- as.vector(unlist(raw$transactions[1], recursive = T, use.names = F))
for (i in 2:length(raw$transactions)) {
row <- as.vector(unlist(raw$transactions[i], recursive = T, use.names = F))
temp_2 <- rbind(temp_2, row)
}
colnames(temp_2) <- c('t_username', 't_picture', 't_is_business', 't_name', 't_firstname', 't_lastname', 't_cancelled', 't_date_created', 't_external_id', 't_id')
trans <- cbind(temp_1, raw$actor, temp_2)
return(trans)
}
# implement (sample)
url = 'https://venmo.com/api/v5/public?limit=50'
trans = transaction_data(url)
# gather data for 'x' amount of time
dfs <- list()
for (i in 1:25) {
Sys.sleep(10)
tryCatch({temp = transaction_data(url)}, error=function(e) {Sys.sleep(10)})
dfs[[i]] <- temp
print(paste(i, ": No Error"))
}
trans <- data.frame(do.call(rbind, dfs))
# save copy as .csv file
filename = paste('venmo-public-payments-raw-', Sys.Date(), '.csv', sep = '')
write.csv(trans, file = filename, row.names = F)
# extract 'interesting' information
df <- trans %>%
mutate(date_created = substr(date_created, 1, 10)) %>%
select(`Payment ID` = payment_id,
`Payment Date & Time` = updated_time,
From = name,
`User Since` = date_created,
Type = type,
To = t_name,
Message = message)
# save copy as .csv file
filename = paste('venmo-public-payments-interesting', Sys.Date(), '.csv', sep = '')
write.csv(df, file = filename, row.names = F)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.