Advertisement
themaleem

Untitled

Jul 5th, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.74 KB | None | 0 0
  1. library(httr)
  2. library(utils)
  3.  
  4. url_path <- 'https://data.police.uk/data/archive/2022-12.zip'
  5.  
  6. # Make a GET request to the URL and stream the response
  7. response <- httr::GET(url_path, stream = TRUE)
  8.  
  9. # Open a connection to the streamed response
  10. con <- rawConnection(response$content, "rb")
  11.  
  12. # Open the connection as a .zip file
  13. zip_file <- unzip(con, exdir = ".", list = TRUE)
  14.  
  15. # Iterate over the files in the .zip file
  16. for (file_name in zip_file$Name) {
  17.   if (grepl("\\.street\\.", file_name)) {
  18.     print(file_name)
  19.     # Extract the file into the current working directory
  20.     unzip(con, files = file_name, exdir = ".", junkpaths = TRUE)
  21.     print(paste0("Finished saving ", file_name))
  22.   }
  23. }
  24.  
  25. # Close the connection
  26. close(con)
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement