Skip to content

Commit

Permalink
furhter fix of docker
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminguinaudeau committed Nov 29, 2020
1 parent f98b8a3 commit 2538ed8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 4 additions & 2 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ get_n <- function(scope, n = 10000, start_date = lubridate::dmy("01-01-1900"), c
#' @param url url to visit and get data from
#' @param parse logical. whether to return parsed data or not. Defautls to \code{TRUE}.
#' @export
get_data <- function(url, parse = T, vpn = F, cookie = "", time_out = 10, docker = F){
get_data <- function(url, parse = T, vpn = F, cookie = "", time_out = 10){



if(!stringr::str_detect(url, "&_signature=")){
final_url <- get_signature(url, docker = docker)
final_url <- get_signature(url)
} else {
final_url <- url
}
Expand Down
2 changes: 2 additions & 0 deletions R/meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ tk_auth <- function(cookie, ua, id_cookie, docker = F) {
} else {
message("TIKTOK_DOCKER found. Tiktokr will use a docker container to sign the urls")
}
} else {
if(Sys.getenv("TIKTOK_DOCKER") == "") message("TIKTOK_DOCKER found. Tiktokr will use a docker container to sign the urls")
}

## Tiktok Cookie
Expand Down
11 changes: 6 additions & 5 deletions R/signature.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#' @export
get_signature <- function(urls, docker = F){

if(!docker) out <- get_puppeteer_signature(urls)
if(docker) out <- urls %>% purrr::map_chr(get_docker_signature)
# if(!is.null(port)) out <- urls %>% purrr::map_chr(get_api_signature, port = port)
get_signature <- function(urls){

if(Sys.getenv("TIKTOK_DOCKER") == "TRUE"){
out <- urls %>% purrr::map_chr(get_docker_signature)
} else {
out <- get_puppeteer_signature(urls)
}

paste0(urls, "&_signature=", out)
}
Expand Down
15 changes: 13 additions & 2 deletions lab.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ b$signature
```{r}
dockeR::doc_copy("tiktoksignature", from = "../tiktok_signature/api.R", to_cont = "/usr/api.R")
dockeR::doc_copy("tiktoksignature", from = "../tiktok_signature/run_api.R", to_cont = "/usr/run_api.R")
Expand All @@ -42,11 +48,16 @@ res$r_code

1. Install docker. Once it is installed you can verify with `docker -v```

2. Build the image of a container able to generate tiktok signature (this needs to be done only once)
2. Set `docker = T` in tk_auth() and run the following test:

```{r}
tk_init()
if(stringr::str_length(get_docker_signature("")) > 16){
message("Signature successfull, your docker container is working.")
} else {
message("Unable to get the signature")
}
```

Expand Down

0 comments on commit 2538ed8

Please sign in to comment.