Skip to content

Commit

Permalink
fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
JBGruber committed Mar 13, 2024
1 parent 20ca770 commit a275799
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
22 changes: 15 additions & 7 deletions R/api_research.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
#' @param is_random Whether the query is random (defaults to FALSE)
#' @param max_pages results are returned in batches/pages with 100 videos. How
#' many should be requested before the function stops?
#' @param parse Should the results be parsed? Otherwise, the original JSON
#' object is returned as a nested list.
#' @param cache should progress be saved in the current session? It can then be
#' retrieved with \code{last_query()} if an error occurs. But the function
#' will use extra memory.
#' @param verbose should the function print status updates to the screen?
#' @param token The authentication token (usually supplied automatically after
#' running auth_research once)
#' @return A data.frame of parsed TikTok videos
#' @return A data.frame of parsed TikTok videos (or a nested list).
#' @export
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -72,6 +74,7 @@ tt_search_api <- function(query,
search_id = NULL,
is_random = FALSE,
max_pages = 1,
parse = TRUE,
cache = TRUE,
verbose = TRUE,
token = NULL) {
Expand Down Expand Up @@ -156,14 +159,19 @@ tt_search_api <- function(query,
if (verbose) cli::cli_progress_done()
}

if (verbose) {
cli::cli_progress_done()
cli::cli_progress_step("Parsing data")
if (parse) {
if (verbose) {
cli::cli_progress_done()
cli::cli_progress_step("Parsing data")
}
videos <- parse_api_search(videos)
if (verbose) cli::cli_progress_done()
} else {
attr(videos, "search_id") <- the$search_id
attr(videos, "cursor") <- the$cursor
}
out <- parse_api_search(videos)

if (verbose) cli::cli_progress_done()
return(out)
return(videos)
}


Expand Down
2 changes: 2 additions & 0 deletions R/parse_research.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ parse_api_search <- function(x) {
author_name = vpluck(x, "username", val = "character"),
view_count = vpluck(x, "view_count", val = "integer"),
comment_count = vpluck(x, "comment_count", val = "integer"),
share_count = vpluck(x, "share_count", val = "integer"),
like_count = vpluck(x, "like_count", val = "integer"),
region_code = vpluck(x, "region_code", val = "character"),
create_time = as.POSIXct(vpluck(x, "create_time", val = "integer"),
tz = "UTC", origin = "1970-01-01"),
Expand Down
7 changes: 6 additions & 1 deletion man/tt_search_api.Rd

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

0 comments on commit a275799

Please sign in to comment.