Last active
April 7, 2019 04:49
-
-
Save markwk/bd9e0b109110a943d32548291e91a241 to your computer and use it in GitHub Desktop.
Readings Files Tracker: Ebooks and PDFs Files Tracking, including number of files tagged with blue, red, etc.
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
# !/bin/bash | |
############################# | |
# Readings Tracker | |
# | |
# Watch Directories of Articles and Book Files for new and modified files | |
# | |
# (Mac) Track Tagged PDF and other Files using command line tool Tag: https://github.com/jdberry/tag | |
# | |
# Data Tracking and Log Files | |
DATA_FILE="/Users/user/Development/data/files-reading-stats.csv" | |
# modified files log | |
LOG_FILE="/Users/user/Development/data/files-log.csv" | |
# files currently tagged | |
TAGS_LOG="/Users/user/Development/data/tagged-files-log.csv" | |
# Articles Directory (Typically where you store PDFs. I use Bookends.): | |
ART_DIR=~/Documents/Bookends/Attachments | |
# Books Directory (Typically where you store eBooks. I use Calibre to manage this.) | |
BOOKS_DIR=~/Documents/personal/Book Library | |
# Processing directory of downloads (Typically a processing directory for ebooks or pdfs.) | |
PROC_DIR=~/Desktop/processing | |
# Data Tracking and Log Files | |
DATA_FILE="/Users/user/Development/data/files-reading-stats.csv" | |
# modified files log | |
LOG_FILE="/Users/user/Development/data/files-log.csv" | |
# files currently tagged | |
TAGS_LOG="/Users/user/Development/data/tagged-files-log.csv" | |
# | |
############################ | |
CURRENTDATETIME=`date +"%Y-%m-%d %T"` | |
CURRENTDATE=`date +"%Y-%m-%d"` | |
YESTERDAY=`date -v-1d +%F` | |
echo "${CURRENTDATETIME}: Starting Files Tracking Analysis" | |
# Basic tagged files stats | |
red_tags="$(tag --find Red | wc -l | tr -d '[:space:]')" | |
blue_tags="$(tag --find Blue | wc -l | tr -d '[:space:]')" | |
purple_tags="$(tag --find Purple | wc -l | tr -d '[:space:]')" | |
green_tags="$(tag --find Green | wc -l | tr -d '[:space:]')" | |
yellow_tags="$(tag --find Yellow | wc -l | tr -d '[:space:]')" | |
orange_tags="$(tag --find Orange | wc -l | tr -d '[:space:]')" | |
gray_tags="$(tag --find Gray | wc -l | tr -d '[:space:]')" | |
echo "$YESTERDAY Tagged #s: $red_tags, $blue_tags, $purple_tags, $green_tags, $orange_tags, $gray_tags" | |
# Daily log of tagged files | |
declare -a arr=("Red" "Blue" "Purple" "Green" "Yellow" "Orange" "Gray") | |
for i in "${arr[@]}" | |
do | |
echo "Processing $i Tags..." | |
tag --find $i | while read line; do | |
file="$(basename $line | tr -d ,)" | |
# echo $file | |
echo ${YESTERDAY},${CURRENTDATETIME},${file},$i >> $TAGS_LOG | |
done | |
done | |
cd $ART_DIR | |
art_total_files="$(find * \( ! -regex '.*/\..*' \) -not -name '*.db' -not -name '*.json' -not -name '*.opf' -not -name '*.jpg' -not -name '*.png' -type f | wc -l | tr -d '[:space:]')" | |
# Store a list of recent modifed files to log | |
find * \( ! -regex '.*/\..*' \) -not -name '*.jpg' -not -name '*.png' -mtime -1 -type f -exec basename {} \; | while read line; do | |
file="$(echo $line | tr -d ,)" | |
echo ${YESTERDAY},${CURRENTDATETIME},${file}>> $LOG_FILE | |
done | |
art_changed="$(find * \( ! -regex '.*/\..*' \) -not -name '*.jpg' -not -name '*.png' -mtime -1 -ls -type f | wc -l | tr -d '[:space:]')" | |
# QUESTION: Can we keep a log of newly aded files? | |
echo "Articles: total files: $art_total_files, changed: $art_changed" | |
cd "$BOOKS_DIR" | |
book_total_files="$(find . \( ! -regex '.*/\..*' \) -not -name '*.db' -not -name '*.json' -not -name '*.opf' -not -name '*.jpg' -not -name '*.png' -type f | wc -l | tr -d '[:space:]')" | |
book_changed="$(find . \( ! -regex '.*/\..*' \) -not -name '*.db' -not -name '*.json' -not -name '*.opf' -not -name '*.jpg' -not -name '*.png' -mtime -1 -ls -type f | wc -l | tr -d '[:space:]')" | |
find . \( ! -regex '.*/\..*' \) -not -name '*.db' -not -name '*.json' -not -name '*.opf' -not -name '*.jpg' -not -name '*.png' -mtime -1 -type f -exec basename {} \; | while read line; do | |
file="$(echo $line | tr -d ,)" | |
echo ${YESTERDAY},${CURRENTDATETIME},${file} >> $LOG_FILE | |
done | |
echo "Books: total files: $book_total_files, changed: $book_changed" | |
cd $PROC_DIR | |
proc_total_files="$(find . \( ! -regex '.*/\..*' \) -type f | wc -l | tr -d '[:space:]')" | |
# TODO: Keep log recently added files for processing | |
#find * \( ! -regex '.*/\..*' \) -not -name '*.jpg' -not -name '*.png' -mtime -1 -type f -exec basename {} \; | while read line; do | |
# file="$(echo $line | tr -d ,)" | |
# echo ${YESTERDAY},${CURRENTDATETIME},${file}>> $LOG_FILE | |
#done | |
proc_changed="$(find . \( ! -regex '.*/\..*' \) -mtime -1 -ls -type f | wc -l | tr -d '[:space:]')" | |
# QUESTION: Can we keep a log of newly aded files? | |
echo "Prcoessing: total files: $proc_total_files, changed: $proc_changed" | |
# Save Stats to CSV | |
echo ${YESTERDAY}, ${CURRENTDATETIME}, $art_total_files, $art_changed, $book_total_files, $book_changed, $proc_total_files, $proc_changed, $red_tags, $blue_tags, $purple_tags, $green_tags, $orange_tags, $gray_tags, $yellow_tags >> $DATA_FILE | |
# mac notification | |
osascript -e 'display notification "Successfully stored your files reading stats." with title "Yesterday Files Reading Stats Saved"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment