Skip to content

Commit

Permalink
add follow_fun for athl_fun #99
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Oct 15, 2023
1 parent 2982cf3 commit 5a3ad68
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export(compile_club_activities)
export(compile_seg_effort)
export(compile_seg_efforts)
export(compile_segment)
export(follow_fun)
export(get_KOMs)
export(get_activity)
export(get_activity_list)
Expand Down
4 changes: 4 additions & 0 deletions R/athlind_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ athlind_fun <- function(athl_num){
# get athlete location
loc <- location_fun(prsd)

# get follower data
follow <- follow_fun(prsd)

# monthly data from bar plot
monthly <- monthly_fun(prsd)

Expand All @@ -50,6 +53,7 @@ athlind_fun <- function(athl_num){
out <- list(
name = name,
location = loc,
follow = follow,
monthly = monthly,
recent= recent,
trophies = trophies,
Expand Down
32 changes: 32 additions & 0 deletions R/follow_fun.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Get athlete follow data
#'
#' Get athlete follow data, used internally in \code{\link{athl_fun}}
#'
#' @param prsd parsed input list
#'
#' @export
#'
#' @concept notoken
#'
#' @return A data frame of counts of followers and following for the athlete. An empty list is returned if none found.
follow_fun <- function(prsd){

follow <- prsd %>%
rvest::html_elements(".Details_followStats__Pwe6T")

if(length(follow) == 0)
return(list())

labs <- follow %>%
rvest::html_elements(".Stat_statLabel___khR4") %>%
xml2::xml_text()
fols <- follow %>%
rvest::html_elements(".Stat_statValue__3_kAe") %>%
xml2::xml_text()

out <- data.frame(matrix(fols, ncol = length(labs)))
names(out) <- labs

return(out)

}
1 change: 0 additions & 1 deletion R/trophy_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#' @return A data frame of trophies for the athlete. An empty list is returned if none found.
trophy_fun <- function(prsd){

# xml_find_all(parsed_xml, './/title')
trophies <- prsd %>%
rvest::html_elements(".Trophy_description__EcC86")

Expand Down
18 changes: 18 additions & 0 deletions man/follow_fun.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a3ad68

Please sign in to comment.