v0.0.1-rollbackpoint
This commit is contained in:
@@ -3,4 +3,4 @@ export JOPLIN_PORT="41185"
|
|||||||
export JOPLIN_API_TOKEN="3f01c4a9f06f7696178b1b93b2db4e3d5b85d42ad35308dcf036670c97aff77c4062bb4454addbc98d0bc01142d5b530171ae47e5c650598aa82ca5b8c51ac3e"
|
export JOPLIN_API_TOKEN="3f01c4a9f06f7696178b1b93b2db4e3d5b85d42ad35308dcf036670c97aff77c4062bb4454addbc98d0bc01142d5b530171ae47e5c650598aa82ca5b8c51ac3e"
|
||||||
|
|
||||||
export JOPLIN_NOTE_TITLE="DSR-Template"
|
export JOPLIN_NOTE_TITLE="DSR-Template"
|
||||||
export JOPLIN_NOTEBOOK_PATH="@DailyStakeholderReports/Today"
|
export JOPLIN_NOTEBOOK_PATH="Today"
|
||||||
|
@@ -5,6 +5,10 @@
|
|||||||
[INFO] Starting the note cloning process.
|
[INFO] Starting the note cloning process.
|
||||||
[INFO] Current date retrieved: 2024-12-18.
|
[INFO] Current date retrieved: 2024-12-18.
|
||||||
[INFO] Fetching original note by title: DSR-Template.
|
[INFO] Fetching original note by title: DSR-Template.
|
||||||
|
[INFO] Fetching note by title: DSR-Template.
|
||||||
|
[DEBUG] Fetching page: 1
|
||||||
|
[DEBUG] Fetching page: 2
|
||||||
|
[DEBUG] Fetching page: 3
|
||||||
[DEBUG] Consolidated note JSON: [
|
[DEBUG] Consolidated note JSON: [
|
||||||
{
|
{
|
||||||
"id": "8cb08d22fd9f433dbaaa15f75a79bd22",
|
"id": "8cb08d22fd9f433dbaaa15f75a79bd22",
|
||||||
@@ -1066,6 +1070,56 @@ DSR-12-17-2024
|
|||||||
DSR-12-18-2024
|
DSR-12-18-2024
|
||||||
DSR-Template
|
DSR-Template
|
||||||
[DEBUG] Matched note JSON: {"id":"d72c30b9ac4844baa8bd5d8312629fca","parent_id":"5d7e4218b48d4e7ba38bd8bcd4f4f6b8","title":"DSR-Template","deleted_time":0}
|
[DEBUG] Matched note JSON: {"id":"d72c30b9ac4844baa8bd5d8312629fca","parent_id":"5d7e4218b48d4e7ba38bd8bcd4f4f6b8","title":"DSR-Template","deleted_time":0}
|
||||||
[INFO] Successfully fetched the original note. Extracting note ID.
|
[DEBUG] Raw original note JSON: {"id":"d72c30b9ac4844baa8bd5d8312629fca","parent_id":"5d7e4218b48d4e7ba38bd8bcd4f4f6b8","title":"DSR-Template","deleted_time":0}
|
||||||
jq: parse error: Invalid numeric literal at line 1, column 6
|
[INFO] Fetching full details of the note with ID: d72c30b9ac4844baa8bd5d8312629fca.
|
||||||
Error: Failed to extract note ID from the original note.
|
[DEBUG] Full note JSON: {"id":"d72c30b9ac4844baa8bd5d8312629fca","parent_id":"5d7e4218b48d4e7ba38bd8bcd4f4f6b8","title":"DSR-Template","deleted_time":0,"type_":1}
|
||||||
|
[INFO] Extracted body: [No content]
|
||||||
|
[INFO] Fetching notebook ID for path: Today.
|
||||||
|
[INFO] Fetching notebook ID for path: Today.
|
||||||
|
[DEBUG] Available folders:
|
||||||
|
HFNOC-v1
|
||||||
|
Docs RR
|
||||||
|
Legacy Resumes
|
||||||
|
VP Technical Operations
|
||||||
|
VP Treasury Operations
|
||||||
|
Systems Setup
|
||||||
|
VP Marketing
|
||||||
|
VPFundraising
|
||||||
|
VpSales
|
||||||
|
RackRental
|
||||||
|
2-HFNOC-v1
|
||||||
|
Resume
|
||||||
|
ReachableCEO.com
|
||||||
|
@ReachableCEO
|
||||||
|
@TSYSPublic
|
||||||
|
Chief Commons Officer
|
||||||
|
Chief Operations Officer
|
||||||
|
Chief Technology Officer
|
||||||
|
Board
|
||||||
|
@Skillup
|
||||||
|
@Clips
|
||||||
|
Conflicts (attachments)
|
||||||
|
Employment
|
||||||
|
Founder
|
||||||
|
MBA
|
||||||
|
ImportMove
|
||||||
|
KB
|
||||||
|
@DailyStakeholderReports
|
||||||
|
Today
|
||||||
|
PostedToDiscourse
|
||||||
|
Template
|
||||||
|
StrategicPlans
|
||||||
|
Reading List
|
||||||
|
Redmine Inbox
|
||||||
|
Web Posts
|
||||||
|
Published To Ghost
|
||||||
|
newsletter.reachableceo.com
|
||||||
|
From The Desk of the @ReachableCEO
|
||||||
|
From The Desk of the CTO
|
||||||
|
EDC
|
||||||
|
[INFO] Notebook ID for path Today: a291e4667b8f4d45b62edae0573bf392.
|
||||||
|
[INFO] Notebook ID retrieved: a291e4667b8f4d45b62edae0573bf392. Creating the new note.
|
||||||
|
[INFO] Creating a new note with title: DSR-2024-12-18.
|
||||||
|
{"title":"DSR-2024-12-18","body":"[No content]","parent_id":"a291e4667b8f4d45b62edae0573bf392","markup_language":1,"updated_time":1734561956441,"created_time":1734561956441,"user_updated_time":1734561956441,"user_created_time":1734561956441,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","order":1734561956442,"deleted_time":0,"id":"09b3f43ce3214cf78f60fa656620ea5d","type_":1}[INFO] Note titled DSR-2024-12-18 created successfully.
|
||||||
|
[INFO] Successfully cloned note to DSR-2024-12-18 in notebook Today.
|
||||||
|
[INFO] Script execution completed successfully.
|
@@ -6,11 +6,14 @@
|
|||||||
# v1 https://chatgpt.com/share/6750c7df-6b2c-8005-a91c-1bc5b3875170
|
# v1 https://chatgpt.com/share/6750c7df-6b2c-8005-a91c-1bc5b3875170
|
||||||
# i have learned much more about chatpgpt/prompting etc in the interim and give you
|
# i have learned much more about chatpgpt/prompting etc in the interim and give you
|
||||||
# V2 on 12/18/2024: https://chatgpt.com/share/676337f2-7414-8005-b3cc-9cc5b6e5ec18
|
# V2 on 12/18/2024: https://chatgpt.com/share/676337f2-7414-8005-b3cc-9cc5b6e5ec18
|
||||||
|
# v2.1 https://chatgpt.com/share/676337f2-7414-8005-b3cc-9cc5b6e5ec18
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
# Start of script
|
# Start of script
|
||||||
####################################################
|
####################################################
|
||||||
|
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright (C) $(date +%Y) ReachableCEO Enterprises LLC
|
# Copyright (C) $(date +%Y) ReachableCEO Enterprises LLC
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@@ -35,8 +38,8 @@ ENV_FILE="../DSRVariables.env"
|
|||||||
echo "[INFO] Sourcing environment variables from $ENV_FILE."
|
echo "[INFO] Sourcing environment variables from $ENV_FILE."
|
||||||
if [[ ! -f "$ENV_FILE" ]]; then
|
if [[ ! -f "$ENV_FILE" ]]; then
|
||||||
|
|
||||||
echo "Error: Environment file not found at $ENV_FILE." >&2
|
echo "Error: Environment file not found at $ENV_FILE." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -48,12 +51,12 @@ echo "[INFO] Environment variables sourced successfully."
|
|||||||
REQUIRED_VARS=(JOPLIN_NOTE_TITLE JOPLIN_HOST JOPLIN_PORT JOPLIN_NOTEBOOK_PATH)
|
REQUIRED_VARS=(JOPLIN_NOTE_TITLE JOPLIN_HOST JOPLIN_PORT JOPLIN_NOTEBOOK_PATH)
|
||||||
for var in "${REQUIRED_VARS[@]}"; do
|
for var in "${REQUIRED_VARS[@]}"; do
|
||||||
|
|
||||||
if [[ -z "${!var}" ]]; then
|
if [[ -z "${!var}" ]]; then
|
||||||
|
|
||||||
echo "Error: $var is not set or is null. Please check your environment file." >&2
|
echo "Error: $var is not set or is null. Please check your environment file." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -67,21 +70,36 @@ function get_notebook_id()
|
|||||||
|
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
|
||||||
echo "[INFO] Fetching notebook ID for path: $path."
|
echo "[INFO] Fetching notebook ID for path: $path." >&2
|
||||||
local result
|
|
||||||
result=$(curl -sf -X GET \
|
# Fetch all notebook folders
|
||||||
|
local folders
|
||||||
|
folders=$(curl -sf -X GET \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"http://$JOPLIN_HOST:$JOPLIN_PORT/folders?token=$JOPLIN_API_TOKEN" | \
|
"http://$JOPLIN_HOST:$JOPLIN_PORT/folders?token=$JOPLIN_API_TOKEN")
|
||||||
jq -r ".items[] | select(.title == \"$path\") | .id")
|
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
|
|
||||||
echo "Error: Failed to fetch notebook ID for path $path." >&2
|
echo "Error: Failed to fetch folders from Joplin." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] Notebook ID for path $path: $result."
|
echo "[DEBUG] Available folders:" >&2
|
||||||
|
echo "$folders" | jq -r '.items[] | .title' >&2
|
||||||
|
|
||||||
|
# Match the exact folder
|
||||||
|
local result
|
||||||
|
result=$(echo "$folders" | jq -r ".items[] | select(.title == \"$path\") | .id")
|
||||||
|
|
||||||
|
if [[ $? -ne 0 || -z "$result" ]]; then
|
||||||
|
|
||||||
|
echo "Error: No matching notebook found for path: $path. Available notebooks are listed above." >&2
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[INFO] Notebook ID for path $path: $result." >&2
|
||||||
echo "$result"
|
echo "$result"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -92,12 +110,13 @@ function get_note_by_title()
|
|||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
echo "[INFO] Fetching note by title: $JOPLIN_NOTE_TITLE."
|
echo "[INFO] Fetching note by title: $JOPLIN_NOTE_TITLE." >&2
|
||||||
local raw_response="[]"
|
local raw_response="[]"
|
||||||
local page=1
|
local page=1
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
|
|
||||||
|
echo "[DEBUG] Fetching page: $page" >&2
|
||||||
local response
|
local response
|
||||||
response=$(curl -sf -X GET \
|
response=$(curl -sf -X GET \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
@@ -110,7 +129,7 @@ function get_note_by_title()
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract items from the response and append to raw_response
|
# Extract items and merge them
|
||||||
local items
|
local items
|
||||||
items=$(echo "$response" | jq -c '.items')
|
items=$(echo "$response" | jq -c '.items')
|
||||||
|
|
||||||
@@ -118,7 +137,6 @@ function get_note_by_title()
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Merge arrays using jq
|
|
||||||
raw_response=$(echo "$raw_response" "$items" | jq -s 'add')
|
raw_response=$(echo "$raw_response" "$items" | jq -s 'add')
|
||||||
page=$((page + 1))
|
page=$((page + 1))
|
||||||
|
|
||||||
@@ -163,7 +181,7 @@ function create_new_note()
|
|||||||
local body="$2"
|
local body="$2"
|
||||||
local parent_id="$3"
|
local parent_id="$3"
|
||||||
|
|
||||||
echo "[INFO] Creating a new note with title: $title."
|
echo "[INFO] Creating a new note with title: $title." >&2
|
||||||
curl -sf -X POST \
|
curl -sf -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "$(jq -n --arg title "$title" --arg body "$body" --arg parent_id "$parent_id" \
|
-d "$(jq -n --arg title "$title" --arg body "$body" --arg parent_id "$parent_id" \
|
||||||
@@ -177,7 +195,7 @@ function create_new_note()
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] Note titled $title created successfully."
|
echo "[INFO] Note titled $title created successfully." >&2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,9 +205,10 @@ function clone_note_with_date()
|
|||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
echo "[INFO] Starting the note cloning process."
|
echo "[INFO] Starting the note cloning process." >&2
|
||||||
local current_date
|
local current_date
|
||||||
current_date=$(date +%Y-%m-%d)
|
current_date=$(date +%Y-%m-%d)
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
|
|
||||||
echo "Error: Failed to retrieve the current date." >&2
|
echo "Error: Failed to retrieve the current date." >&2
|
||||||
@@ -197,12 +216,13 @@ function clone_note_with_date()
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] Current date retrieved: $current_date."
|
echo "[INFO] Current date retrieved: $current_date." >&2
|
||||||
local new_title="DSR-$current_date"
|
local new_title="DSR-$current_date"
|
||||||
|
|
||||||
echo "[INFO] Fetching original note by title: $JOPLIN_NOTE_TITLE."
|
echo "[INFO] Fetching original note by title: $JOPLIN_NOTE_TITLE." >&2
|
||||||
local original_note
|
local original_note
|
||||||
original_note=$(get_note_by_title)
|
original_note=$(get_note_by_title)
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
|
|
||||||
echo "Error: Failed to fetch the note with title $JOPLIN_NOTE_TITLE." >&2
|
echo "Error: Failed to fetch the note with title $JOPLIN_NOTE_TITLE." >&2
|
||||||
@@ -210,9 +230,12 @@ function clone_note_with_date()
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] Successfully fetched the original note. Extracting note ID."
|
echo "[DEBUG] Raw original note JSON: $original_note" >&2
|
||||||
|
|
||||||
|
# Extract the note ID
|
||||||
local note_id
|
local note_id
|
||||||
note_id=$(echo "$original_note" | jq -r '.id')
|
note_id=$(echo "$original_note" | jq -r '.id')
|
||||||
|
|
||||||
if [[ $? -ne 0 || -z "$note_id" ]]; then
|
if [[ $? -ne 0 || -z "$note_id" ]]; then
|
||||||
|
|
||||||
echo "Error: Failed to extract note ID from the original note." >&2
|
echo "Error: Failed to extract note ID from the original note." >&2
|
||||||
@@ -220,7 +243,7 @@ function clone_note_with_date()
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] Fetching full details of the note with ID: $note_id."
|
echo "[INFO] Fetching full details of the note with ID: $note_id." >&2
|
||||||
local full_note
|
local full_note
|
||||||
full_note=$(curl -sf -X GET \
|
full_note=$(curl -sf -X GET \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
@@ -235,21 +258,23 @@ function clone_note_with_date()
|
|||||||
|
|
||||||
echo "[DEBUG] Full note JSON: $full_note" >&2
|
echo "[DEBUG] Full note JSON: $full_note" >&2
|
||||||
|
|
||||||
# Extract 'body' field or use a default value
|
# Extract 'body' from the full note
|
||||||
local body
|
local body
|
||||||
body=$(echo "$full_note" | jq -r 'if .body != null and .body != "" then .body else "[No content]" end')
|
body=$(echo "$full_note" | jq -r '.body // "[No content]"')
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
|
|
||||||
echo "Error: Failed to process the body from the full note details." >&2
|
echo "Error: Failed to extract body from the note details." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] Extracted body from the full note details."
|
echo "[INFO] Extracted body: $body" >&2
|
||||||
|
|
||||||
echo "[INFO] Fetching notebook ID for path: $JOPLIN_NOTEBOOK_PATH."
|
echo "[INFO] Fetching notebook ID for path: $JOPLIN_NOTEBOOK_PATH." >&2
|
||||||
local notebook_id
|
local notebook_id
|
||||||
notebook_id=$(get_notebook_id "$JOPLIN_NOTEBOOK_PATH")
|
notebook_id=$(get_notebook_id "$JOPLIN_NOTEBOOK_PATH")
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
|
|
||||||
echo "Error: Failed to fetch notebook ID for path $JOPLIN_NOTEBOOK_PATH." >&2
|
echo "Error: Failed to fetch notebook ID for path $JOPLIN_NOTEBOOK_PATH." >&2
|
||||||
@@ -257,35 +282,30 @@ function clone_note_with_date()
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$notebook_id" ]]; then
|
echo "[INFO] Notebook ID retrieved: $notebook_id. Creating the new note." >&2
|
||||||
|
|
||||||
echo "Error: Notebook path $JOPLIN_NOTEBOOK_PATH does not exist." >&2
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[INFO] Notebook ID retrieved: $notebook_id. Creating the new note."
|
|
||||||
create_new_note "$new_title" "$body" "$notebook_id"
|
create_new_note "$new_title" "$body" "$notebook_id"
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
|
|
||||||
echo "Error: Failed to create the new note titled $new_title." >&2
|
echo "Error: Failed to create the note titled $new_title." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] Successfully cloned note to $new_title in notebook $JOPLIN_NOTEBOOK_PATH."
|
echo "[INFO] Successfully cloned note to $new_title in notebook $JOPLIN_NOTEBOOK_PATH." >&2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main entry point
|
# Main function
|
||||||
|
|
||||||
function main()
|
function main()
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
echo "[INFO] Script execution started."
|
echo "[INFO] Script execution started." >&2
|
||||||
clone_note_with_date
|
clone_note_with_date
|
||||||
echo "[INFO] Script execution completed successfully."
|
echo "[INFO] Script execution completed successfully." >&2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user