Created
November 11, 2024 22:33
-
-
Save brancengregory/48c60bf7620423ef866bb65b4d03febc to your computer and use it in GitHub Desktop.
Chrome History in R with DuckDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(duckdb) | |
library(duckplyr) | |
library(dplyr) | |
chrome_history_path <- "./chrome_history.sqlite" | |
# Copy the db to the local directory because Chrome puts a lock on it | |
file.copy( | |
"~/.config/google-chrome/Default/History", # Adjust based on OS | |
chrome_history_path, | |
overwrite = TRUE | |
) | |
# Connect to DuckDB | |
con <- dbConnect(duckdb::duckdb()) | |
# Load SQLite extension if not already loaded | |
dbExecute(con, "INSTALL sqlite;") | |
dbExecute(con, "LOAD sqlite;") | |
# Path to the Chrome history SQLite database | |
# Attach the SQLite database | |
attach_query <- paste0("ATTACH DATABASE '", chrome_history_path, "' AS chrome_history (TYPE sqlite);") | |
dbExecute(con, attach_query) | |
# Check out a table | |
tbl(con, "chrome_history.urls") | |
# Close the connection | |
dbDisconnect(con, shutdown = TRUE) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment