aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/backup.sh29
-rwxr-xr-xbin/habit29
-rw-r--r--bin/kindlenotes2org.py54
-rwxr-xr-xbin/tagmail38
4 files changed, 113 insertions, 37 deletions
diff --git a/bin/backup.sh b/bin/backup.sh
index 8a27847..9f53249 100755
--- a/bin/backup.sh
+++ b/bin/backup.sh
@@ -1,11 +1,12 @@
#! /bin/bash
+set -e
backup_local() {
# external program to supply the passphrase:
export BORG_PASSCOMMAND="pass show $1" # repo pass first arg
# Create Local Backups
- echo $(date) "Creating Local Backups ..."
+ echo "$(date) -- Creating Local Backups ..."
REPOSITORY=$2 # repo vault path second arg
shift 2 # consume the first 2 arguments
borg create --list --filter AME --stats --compression=lz4 \
@@ -28,22 +29,34 @@ backup_local() {
--exclude '*/mpd/log' \
--exclude '*/elpa' \
--exclude '*.elc' \
+ --exclude '*/*.o' \
+ --exclude '*/guix/*/*.go' \
+ --exclude '*/guix/*/*.Po' \
+ --exclude '*/guix/*/*.m4' \
--exclude '*/.local/straight' \
--exclude '*/phd/simulation_data' \
- $REPOSITORY::'{hostname}-{user}-{utcnow:%Y-%m-%dT%H:%M:%S}' \
- $@ # all the dirs to bac
+ --exclude '*/semantic-roam' \
+ "$REPOSITORY::{hostname}-{user}-{utcnow:%Y-%m-%dT%H:%M:%S}" \
+ "$@" # all the dirs to bac
# Prune Local Backups
- echo $(date) "Pruning local repository ..."
+ echo "$(date) -- Pruning local repository ..."
borg prune --verbose --stats --list \
--glob-archives='{hostname}-{user}-*' \
--keep-daily 7 \
--keep-weekly 4 \
- --keep-monthly 6 $REPOSITORY
+ --keep-monthly 6 "$REPOSITORY"
}
+BASIC_PATHS=(~/dev/ ~/org/ ~/.mail/ ~/.bogofilter/ ~/Nextcloud/)
+backup_local Admin/sarah/borg/ingrid ssh://borgbackup@sarah/./repos/ingrid "${BASIC_PATHS[@]}"
+
DISK=/run/media/titan/ext_backup
-# backup_local borgbackup ssh://backup/media/Backup/daily_backup/ ~/dev/ ~/.mail/ ~/.bogofilter/ ~/Nextcloud/ ~/org/ "$DISK/personal/Pictures/" "$DISK/personal/Libros/" "$DISK/personal/dev/" "$DISK/Archives/"
-backup_local Admin/sarah/borg/ingrid ssh://borgbackup@173.212.211.30/./repos/ingrid ~/dev/ ~/org/ ~/.mail/ ~/.bogofilter/ ~/Nextcloud/
-backup_local Admin/sarah/borg/oscar ssh://borgbackup@173.212.211.30/./repos/oscar "$DISK/personal/Pictures/" "$DISK/personal/Libros/" "$DISK/personal/dev/" "$DISK/Archives/"
+if [ -d "$DISK" ]; then
+ LARGER_PATHS=("$DISK/personal/Pictures/" "$DISK/personal/Libros/" "$DISK/personal/dev/" "$DISK/Archives/")
+ backup_local Admin/sarah/borg/oscar ssh://borgbackup@sarah/./repos/oscar "${LARGER_PATHS[@]}"
+ if ping -c 1 -W 1 192.168.178.128 >/dev/null; then
+ backup_local borgbackup ssh://backup/media/Backup/daily_backup/ "${BASIC_PATHS[@]}" "${LARGER_PATHS[@]}"
+ fi
+fi
diff --git a/bin/habit b/bin/habit
index 5afb4ce..7c16986 100755
--- a/bin/habit
+++ b/bin/habit
@@ -2,7 +2,10 @@
-e main-rofi -s
!#
-(add-to-load-path "/home/titan/dev/dotfiles/lib/guile/")
+(add-to-load-path
+ (string-append
+ (passwd:dir (getpwuid (geteuid)))
+ "/dev/dotfiles/lib/guile/"))
(use-modules (ice-9 rdelim)
(ice-9 popen)
@@ -17,24 +20,24 @@
(scandir dir (lambda (file) (string-suffix? ".dat" file))))
(define (prepare-options files)
- (string-join (map (lambda (name) (string-drop-right name 4)) files) "\n"))
+ (string-join (map (lambda (f) (basename f ".dat")) files) "\n"))
-(define (rofi-capture-option options)
- (let* ((cmd (format #f "echo -e ~s | rofi -dmenu" options))
- (port (open-input-pipe cmd))
- (option (read-line port)))
+(define (over-shell cmd)
+ (let* ((port (open-input-pipe cmd))
+ (result (read-line port)))
(close-pipe port)
- (if (eof-object? option) #f option)))
+ (if (eof-object? result) #f result)))
+
+(define (rofi-capture-option options)
+ (over-shell (format #f "echo -e ~s | rofi -dmenu" options)))
(define (rofi-capture-habit-quantity habit)
- (let* ((cmd (format #f "echo 1 | rofi -dmenu -p 'Add to ~a'" habit))
- (port (open-input-pipe cmd))
- (quantity (read-line port)))
- (close-pipe port)
- (if (eof-object? quantity) #f quantity)))
+ (over-shell (format #f "echo 1 | rofi -dmenu -p 'Add to ~a'" habit)))
(define (main-rofi args)
- (and-let* ((habit (rofi-capture-option (prepare-options (get-habit-files habits-dir))))
+ (and-let* ((habit (-> (get-habit-files habits-dir)
+ (prepare-options)
+ (rofi-capture-option)))
(quantity (rofi-capture-habit-quantity habit))
(file-out (open-file (string-append habits-dir habit ".dat") "a")))
(format file-out "~d:~a\n" (current-time) quantity)
diff --git a/bin/kindlenotes2org.py b/bin/kindlenotes2org.py
new file mode 100644
index 0000000..1769c8c
--- /dev/null
+++ b/bin/kindlenotes2org.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+r"""
+extract book highlights to orgmode
+==================================
+
+Extracts from exported html notes from kindle to org subtree
+"""
+# Created: Sat Jul 14 02:10:24 2018
+# Author: Óscar Nájera
+# License: GPL-3
+
+import argparse
+from textwrap import fill as filltxt
+
+from bs4 import BeautifulSoup
+
+
+def html_notes2org(page):
+ soup = BeautifulSoup(page, "lxml")
+
+ docs = ""
+ for div in soup.find_all("div"):
+ hcl = div.attrs.get("class")
+ if "bookTitle" in hcl:
+ docs += "* {}".format(div.text.strip())
+ if "authors" in hcl:
+ docs += " -- {}\n".format(div.text.strip())
+ if "sectionHeading" in hcl:
+ docs += "** " + div.text.lstrip()
+ if "noteText" in hcl:
+ docs += "#+begin_quote\n{}\n#+end_quote\n\n".format(
+ filltxt(div.text.strip())
+ )
+
+ return docs
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("file", help="HTML file from kindle export")
+ args = parser.parse_args()
+
+ with open(args.file, "rb") as fid:
+ page = fid.read()
+
+ docs = html_notes2org(page)
+
+ with open("sub.org", "w") as fid:
+ fid.write(docs)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/bin/tagmail b/bin/tagmail
index 52bcc7c..9febae5 100755
--- a/bin/tagmail
+++ b/bin/tagmail
@@ -38,9 +38,9 @@ LD_LIBRARY_PATH=$HOME/.guix-profile/lib exec guile -e main -s "$0" "$@"
(define (delete-email-files! options)
(define (logged-delete file-path)
- (let ((do? (not (option-ref options 'dry-run #f))))
- (simple-format #t " [rm] ~a~%" file-path)
- (if do? (delete-file file-path))))
+ (simple-format #t " [rm] ~a~%" file-path)
+ (unless (option-ref options 'dry-run #f)
+ (delete-file file-path)))
(with-nm-database
(ffi-db (assq-ref options 'mail-repo) 0)
(with-nm-query
@@ -53,14 +53,14 @@ LD_LIBRARY_PATH=$HOME/.guix-profile/lib exec guile -e main -s "$0" "$@"
(define (move-mail! options account query start-dir end-dir)
(define (move-file uidvalidity target-folder)
- (lambda (file)
- (let* ((target-file (new-path (rename-higher file uidvalidity) target-folder))
- (sub-len (string-prefix-length file target-file))
- (do? (not (option-ref options 'dry-run #f))))
- (simple-format #t " [mv] ~a -> ~a~%"
- (substring file sub-len)
- (substring target-file sub-len))
- (when do? (rename-file file target-file)))))
+ (let ((dry-run? (option-ref options 'dry-run #f)))
+ (lambda (file)
+ (let* ((target-file (new-path (rename-higher file uidvalidity) target-folder))
+ (sub-len (string-prefix-length file target-file)))
+ (simple-format #t " [mv] ~a -> ~a~%"
+ (substring file sub-len)
+ (substring target-file sub-len))
+ (unless dry-run? (rename-file file target-file))))))
(let* ((mail-repo (assq-ref options 'mail-repo))
(target-folder (format #f "~a~a/~a" mail-repo account end-dir))
@@ -78,10 +78,11 @@ LD_LIBRARY_PATH=$HOME/.guix-profile/lib exec guile -e main -s "$0" "$@"
(on-all-messages-filenames to-move (move-file uidvalidity target-folder))))))
(define (apply-tags-to-message options tags)
- (lambda (message)
- (simple-format #t " ~a~%" (nm-header message "subject"))
- (unless (option-ref options 'dry-run #f)
- (nm-apply-tags message tags)) #t))
+ (let ((dry-run? (option-ref options 'dry-run #f)))
+ (lambda (message)
+ (simple-format #t " ~a~%" (nm-header message "subject"))
+ (unless dry-run?
+ (nm-apply-tags message tags)) #t)))
(define (log-msg-tag count rule new)
(let* ((query-str (query-with-new rule new))
@@ -178,7 +179,12 @@ LD_LIBRARY_PATH=$HOME/.guix-profile/lib exec guile -e main -s "$0" "$@"
("+meetups" "from:info@meetup.com or from:info@email.meetup.com" "Meetups info mails")
("+immonews" "from:immobilienscout24.de")
("+newsletter" "from:venturebeat.com")
+ ("+zeihan" "from:zeihan.com")
("+freecodecamp" "from:freecodecamp.org")
+ ;; byteplant
+ ("+support" "to:support@byteplant.com")
+ ("+admin" "to:admin@byteplant.com")
+ ("+sent" "from:byteplant.com")
))
(define (clear-inbox options ffi-db)
@@ -201,7 +207,7 @@ LD_LIBRARY_PATH=$HOME/.guix-profile/lib exec guile -e main -s "$0" "$@"
(dry-run (single-char #\n) (value #f))))
(options (append (list (cons 'mail-repo mail-repo)
(cons 'my-emails my-emails))
- (getopt-long args option-spec)))
+ (getopt-long args option-spec)))
(account (assq-ref options '()) ))
(delete-email-files! options)