From f254b397a49381f5ee36980b379fe07a9be4a5c2 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Tue, 29 Aug 2023 12:01:57 -0500 Subject: [PATCH] Forgot this existed --- scripts/make_new.sh | 5 ++--- scripts/update_all.sh | 1 + scripts/update_index.sh | 2 ++ scripts/update_tasks.py | 2 ++ scripts/utils/get-task.sh | 20 ++++++++++++++++++++ scripts/utils/task-db.sql | 14 ++++++++++++++ 6 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 scripts/utils/get-task.sh create mode 100644 scripts/utils/task-db.sql diff --git a/scripts/make_new.sh b/scripts/make_new.sh index a7c9665..ac4275e 100755 --- a/scripts/make_new.sh +++ b/scripts/make_new.sh @@ -1,13 +1,12 @@ #!/usr/bin/bash - JOURNAL_DIR=~/Journal cd $JOURNAL_DIR UPDATE_ALL=$JOURNAL_DIR/scripts/update_all.sh DATE=`date +'%Y-%m-%d'` FILE="$JOURNAL_DIR/$DATE.wiki" -[[ -f $JOURNAL_DIR/utils/journals.sh ]] && . $JOURNAL_DIR/utils/journals.sh +[[ -f $JOURNAL_DIR/scripts/utils/journals.sh ]] && . $JOURNAL_DIR/scripts/utils/journals.sh # Getting the last journal entry file declare -a journals @@ -21,7 +20,7 @@ declare -A topics while read line; do # Stripping the '=' characters from the topic declare -i level=$( tr -cd '=' <<< "$line" | wc -c) - [[ $level -eq 0 ]] && { echo "A line ($line) that was grabbed returned a 0 count level?"; exit 1; } + [[ $level -eq 0 ]] && { echo "A line ($line) that was grabbed returned a 0 count level?"; continue; } # Getting the topic "level" by getting the number of = in the topic and dividing it by 2 # diff --git a/scripts/update_all.sh b/scripts/update_all.sh index 60784ac..1cf3964 100755 --- a/scripts/update_all.sh +++ b/scripts/update_all.sh @@ -1,5 +1,6 @@ #!/usr/bin/bash JOURNAL_DIR=~/Journal +FILES_DIR=$JOURNAL_DIR/files SCRIPT_DIR=$JOURNAL_DIR/scripts/enabled #set -x diff --git a/scripts/update_index.sh b/scripts/update_index.sh index 29ed52e..b6174c4 100755 --- a/scripts/update_index.sh +++ b/scripts/update_index.sh @@ -14,6 +14,8 @@ get_journals journals echo " %title Journal Index [[full_index.wiki|Full Index]] +[[tasks.wiki|Tasks Index]] +[[how-to.wiki|How-To Index]] # Journals $( diff --git a/scripts/update_tasks.py b/scripts/update_tasks.py index 51f2825..9497270 100755 --- a/scripts/update_tasks.py +++ b/scripts/update_tasks.py @@ -3,6 +3,8 @@ from pathlib import Path from utils.py.journals import * +SCRIPT_DIR=Path.home()/"Journal"/"scripts" +SCRIPT_DIR.cwd() TASK_FILE=Path.home()/"Journal"/"tasks.wiki" if not TASK_FILE.exists(): diff --git a/scripts/utils/get-task.sh b/scripts/utils/get-task.sh new file mode 100644 index 0000000..7259e0f --- /dev/null +++ b/scripts/utils/get-task.sh @@ -0,0 +1,20 @@ +#!/usr/bin/bash +: " +get_task_number +This function will query sqlite db to either get the number of a task OR create the task and return the number + +returns: + -1 - Experienced error + 0 - Task was found + 1 - Task was created +" +function get_task_number() { + local DB_PATH="${FILES_DIR:?"FILES_DIR was not set"}/task.db" + local TASK_TITLE="${1:?"Task title was not provided"}" + + local TASK_NUMBER="$( + sqlite3 $DB_PATH <<< " + SELECT + " + )" +} diff --git a/scripts/utils/task-db.sql b/scripts/utils/task-db.sql new file mode 100644 index 0000000..74da425 --- /dev/null +++ b/scripts/utils/task-db.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOT EXISTS tasks ( + TASK_ID INTEGER PRIMARY KEY AUTOINCREMENT, + TASK_TITLE TEXT NOT NULL, + TASK_CREATION_DATE DATETIME DEFAULT CURRENT_TIMESTAMP, + TASK_DUE_DATE DATETIME DEFAULT DATETIME(CURRENT_TIMESTAMP, '+7 day') +); + +CREATE VIEW tasks_by_creation AS + SELECT TASK_ID task_number, TASK_TITLE task_title, DATE(TASK_CREATION_DATE) creation_date FROM tasks + ORDER BY TASK_CREATION_DATE ASC; + +CREATE VIEW tasks_by_duedate AS + SELECT TASK_ID task_number, TASK_TITLE task_title FROM tasks + ORDER BY TASK_DUE_DATE ASC;