nearing working version

This commit is contained in:
2026-08-06 14:56:43 -07:00
parent acb98060b3
commit 37fe9820a7
7 changed files with 40 additions and 15 deletions
+3
View File
@@ -1 +1,4 @@
*.db
*.html
templates/*
Binary file not shown.
Binary file not shown.
+3 -1
View File
@@ -7,7 +7,9 @@ def initBlog(db_file):
id INTEGER PRIMARY KEY,
title TEXT,
body TEXT NOT NULL,
timestamp INTEGER
timestamp INTEGER NOT NULL,
author TEXT,
hidden BOOL NOT NULL DEFAULT FALSE
)
""")
+31 -14
View File
@@ -23,13 +23,29 @@ def mainMenu():
choice = input("Choose an option: ")
return choice
def editText(startingText):
editor = os.environ.get("EDITOR", os.environ.get("VISUAL", "vi"))
with tempfile.NamedTemporaryFile(suffix=".tmp", mode="w+", delete=False) as tf:
tf.write(startingText)
path = tf.name
try:
subprocess.call([editor, path])
with open(path, "r") as f:
return f.read()
finally:
os.unlink(path)
def writeNew(db):
print("""
Write New Post
1. [N]ew Micropost
2. [L]oad Post From File
2. New [F]ull Post
3. [L]oad Post From File
""")
choice = input("Choose an option: ")
@@ -40,6 +56,19 @@ def writeNew(db):
confirmPost = input("Publish this micropost (Y/N)? ")
if confirmPost == 'y' or confirmPost == 'Y':
bbdb.newPost(db, None, post)
elif choice == 'f' or choice == "F" or choice == "2":
newTitle = input("Enter a title for your post: ")
newBody = editText("")
print("\nYour post:")
print('Title: "' + newTitle + '"\nBody:')
print(newBody)
confirmPost = input("Publish this post? (Y/N)? ")
if confirmPost == 'y' or confirmPost == 'Y':
bbdb.newPost(db, newTitle, newBody)
def editPost(db):
try:
@@ -81,19 +110,7 @@ def editPost(db):
else:
print("Updated title.")
elif choice == 'b' or choice == 'B' or choice == "2":
editor = os.environ.get("EDITOR", os.environ.get("VISUAL", "vi"))
with tempfile.NamedTemporaryFile(suffix=".tmp", mode="w+", delete=False) as tf:
tf.write(post["body"])
path = tf.name
try:
subprocess.call([editor, path])
with open(path, "r") as f:
newBody = f.read()
finally:
os.unlink(path)
newBody = editText(post["body"])
print('Your new body text is:\n\n' + newBody + "\n")
confirmEdit = input("Publish this edited post [Y/N]? ")
if confirmEdit == 'y' or confirmEdit == 'Y':
+3
View File
@@ -0,0 +1,3 @@
import markdown
View File