diff options
author | EuAndreh <eu@euandre.org> | 2022-10-31 22:20:29 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-11-01 09:21:16 -0300 |
commit | dcef68452df23f4d63eb53a216cd080ac5803a90 (patch) | |
tree | 9fc0b60f7676cfbae532547e45db2f98c557f5f1 /bin | |
parent | etc/guix/home.scm: Add archivebox package (diff) | |
download | dotfiles-dcef68452df23f4d63eb53a216cd080ac5803a90.tar.gz dotfiles-dcef68452df23f4d63eb53a216cd080ac5803a90.tar.xz |
bin/archiveit: Add new binary, still being validated
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/archiveit | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/bin/archiveit b/bin/archiveit new file mode 100755 index 0000000..da132d7 --- /dev/null +++ b/bin/archiveit @@ -0,0 +1,98 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + archiveit + archiveit -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + + Grab all bookmarks from Firefox that contains tags and archive + them with ArchiveBox. + + + Examples: + + Just run it: + + $ archiveit + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + + +# Derived from ArchiveBox: +# https://github.com/pirate/ArchiveBox/blob/db1f6efc934bbcdf53377bf51a064c6fd0fc5b1d/bin/archivebox-export-browser-history#L23-L37 +QUERY="$( + cat <<-'EOF' + SELECT json_object('timestamp', dateAdded, 'description', title, 'href', url) + FROM ( + SELECT b.dateAdded, b.title, p.url + FROM moz_bookmarks AS b + JOIN moz_places AS p + ON b.fk = p.id + WHERE b.fk IN ( + SELECT DISTINCT(fk) FROM moz_bookmarks + WHERE parent IN ( + -- get all tags + SELECT id FROM moz_bookmarks + WHERE parent = 4 + ) + ) + AND b.title IS NOT NULL + ORDER BY + b.dateAdded ASC, + b.title ASC, + p.url + ) + EOF +)" + +# Copy the database because it is locked. +DB="$(mkstemp)" +cp ~/.mozilla/firefox/*.default/places.sqlite "$DB" + +cd ~/Documents/Archive/ + +sqlite3 "$DB" "$QUERY" | archivebox add +archivebox update |