fix SQLite3 script

This commit is contained in:
2022-09-06 13:03:41 -06:00
parent 5462f9df35
commit a06ca981d8
5 changed files with 17 additions and 82 deletions

View File

@@ -8,7 +8,10 @@ function usage() {
}
[ ! -x "$(command -v sqlite3)" ] && echo "You need SQLite3 to run this" && exit 1
[ -z "$BLOG_DIR" ] && echo '$BLOG_DIR is not set! Defaulting to .' && BLOG_DIR="."
if [ -z "$BLOG_DIR" ]; then
echo "Looking for posts in ./posts because BLOG_DIR is not set."
BLOG_DIR="."
fi
# params -> slug, title, content, date
function update_post() {
@@ -17,33 +20,33 @@ function update_post() {
local title=${3:?Title is required}
local content=${4:?Content is required}
echo "$date" "$slug" "$title" "$content"
echo "Trying to update $slug"
sqlite3 \
"$BLOG_DIR/database.db" \
"UPDATE blog_post SET title = '$title', content = '$content' WHERE slug = '$slug'" 2&> /dev/null
"UPDATE blog_post SET title = '$title', content = '$content' WHERE slug = '$slug'" 2> /dev/null
local status=$?
local status="$?"
[ $status -eq 0 ] && echo "Updated already post: $slug." && return
[[ "$status" = "0" ]] && echo "Successfully updated already existing post: $slug" && return
echo "Failed to update, or insert post: $slug."
}
# params -> slug, title, content, date
function insert_post() {
[ $# -eq 0 ] && exit 1;
[ ! $# -eq 4 ] && exit 1;
local date=${1:?Date is required}
local slug=${2:?Slug is required}
local title=${3:?Title is required}
local content=${4:?Content is required}
sqlite3 "$BLOG_DIR/database.db" "INSERT INTO blog_post (slug, title, content, date) VALUES ('$slug', '$title', '$content', '$date');" 2&> /dev/null
sqlite3 "$BLOG_DIR/database.db" "INSERT INTO blog_post (slug, title, content, date) VALUES ('$slug', '$title', '$content', '$date');" 2> /dev/null
local status=$?
local status="$?"
[ $status -eq 0 ] && echo "Inserted $slug successfully." && return
update_post "$date" "$slug" "$title" "$content"
[ "$status" = "0" ] && echo "Inserted $slug successfully." && return
[ "$status" = "19" ] && echo "Post $slug already exists." && update_post "$date" "$slug" "$title" "$content"
}
# # # # # # # # # # # # # # # # # # # # # # # #

4
post2.post Normal file
View File

@@ -0,0 +1,4 @@
aug 23 2021
test-post
test post
abcdefg test post

View File

@@ -1,62 +0,0 @@
Sep 6, 2022
my-books-for-2022-and-going-into-2023
My books for 2022, and going into 2023
<p>
Here is a compiled list of books that I read in 2022.
(In no particular order)
</p>
<ul>
<li>
<b>The Ruby Programming Language</b> by David Flanagan & Yukihiro Matsumoto (Matz)
</li>
<li>
<b>The Open Organization</b> by Jim Whitehurst
</li>
<li>
<b>Just for Fun</b> by Linus Torvalds & David Diamond
</li>
<li>
<b>Fundamentals of Software Architecture: An Engineering Approach</b> by Mark Richards & Neal Ford
</li>
<li>
<b>Effective C</b> by Robert C. Seacord
</li>
<li>
<b>Nineteen Eighty Four</b> by George Orwell
</li>
<li>
<b>The Idealist</b> by Justin Peters
</li>
</ul>
<p>
The following books are books that I have started but not finished.
I plan to finish these books in 2023.
</p>
<ul>
<li>
<b>An Introduction to Functional Programming Through Lambda Calculus</b> by Greg Michaelson
</li>
<li>
<b>Structure and Interpretation of Computer Programs - 2nd Edition</b> by Harlod Abelson, Gerald Jay Sussman, et al.
</li>
</ul>
<p>
The following are books I have acquired, and plan to read in 2023.
</p>
<ul>
<li>
<b>Nice Work</b> by Claire Hoy
</li>
<li>
<b>Absolute BSD</b> by Michael Lucas & Jordan Hubbard
</li>
<li>
<b>Writing GNU Emacs Extensions: Editor Customizations and Creations with Lisp</b> by Bob Glickstein
</li>
</ul>
<p>
My goal for 2022 was to get better at absorbing useful information from
technical books. I think I met that goal to a good extent, as I was able
to improve my software skills by a good margin this year through the
help of technical literature.
</p>

View File

@@ -1,4 +0,0 @@
Aug 30 2022
blog-testing
Blog Testing
<h1>BASH SCRIPTS adasdFTW</h1>

View File

@@ -1,6 +0,0 @@
Aug 29, 2022
test-post
Test Post
<p>
Some SUPER COOL content.
</p>