Skip to content

Commit

Permalink
Use same handle to recycle cookiejar
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Aug 10, 2024
1 parent 3f9c5eb commit ef37335
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions R/blackbird.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
get_blackbird_count <- function(package){
tryCatch({
url <- paste0('https://github.com/search/blackbird_count?saved_searches=&q=%22library%28', package, '%29%22+path%3A*.R')
warmup <- curl::curl_fetch_memory('https://github.com/', handle = bb_handle('text/html,application/xhtml+xml'))
req <- curl::curl_fetch_memory(url, handle = bb_handle('application/json'))
handle <- make_session_handle()
warmup <- curl::curl_fetch_memory('https://github.com/', handle = curl::handle_setheaders(handle, accept = 'text/html'))
req <- curl::curl_fetch_memory(url, handle = curl::handle_setheaders(handle, accept = 'application/json'))
if(req$status_code != 200){
stop(paste('HTTP', req$status_code))
}
Expand All @@ -18,10 +19,9 @@ get_blackbird_count <- function(package){
})
}

bb_handle <- function(type){
make_session_handle <- function(){
agent <- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
handle <- curl::handle_setheaders(curl::new_handle(useragent = agent),
accept = type, cookie = sprintf('user_session=%s;', Sys.getenv("DUMMY_SESSION")))
curl::new_handle(useragent = agent, cookie = sprintf("user_session=%s;", Sys.getenv("DUMMY_SESSION")))
}

#out <- get_blackbird_count('dplyr')

0 comments on commit ef37335

Please sign in to comment.