diff --git a/.gitignore b/.gitignore index 98e6ef6..650692f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *.db +*.html + +templates/* diff --git a/blahblah/__pycache__/bbdb.cpython-314.pyc b/blahblah/__pycache__/bbdb.cpython-314.pyc index 41f01da..03e673f 100644 Binary files a/blahblah/__pycache__/bbdb.cpython-314.pyc and b/blahblah/__pycache__/bbdb.cpython-314.pyc differ diff --git a/blahblah/__pycache__/main.cpython-314.pyc b/blahblah/__pycache__/main.cpython-314.pyc index 9dbfd2e..afbc2cf 100644 Binary files a/blahblah/__pycache__/main.cpython-314.pyc and b/blahblah/__pycache__/main.cpython-314.pyc differ diff --git a/blahblah/bbdb.py b/blahblah/bbdb.py index bac476b..d881ee6 100644 --- a/blahblah/bbdb.py +++ b/blahblah/bbdb.py @@ -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 ) """) diff --git a/blahblah/main.py b/blahblah/main.py index 89b8e55..442f31e 100644 --- a/blahblah/main.py +++ b/blahblah/main.py @@ -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': diff --git a/blahblah/render.py b/blahblah/render.py new file mode 100644 index 0000000..74d0bc7 --- /dev/null +++ b/blahblah/render.py @@ -0,0 +1,3 @@ +import markdown + + diff --git a/blog. b/blog. new file mode 100644 index 0000000..e69de29