nearing working version
This commit is contained in:
@@ -1 +1,4 @@
|
|||||||
*.db
|
*.db
|
||||||
|
*.html
|
||||||
|
|
||||||
|
templates/*
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+3
-1
@@ -7,7 +7,9 @@ def initBlog(db_file):
|
|||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
title TEXT,
|
title TEXT,
|
||||||
body TEXT NOT NULL,
|
body TEXT NOT NULL,
|
||||||
timestamp INTEGER
|
timestamp INTEGER NOT NULL,
|
||||||
|
author TEXT,
|
||||||
|
hidden BOOL NOT NULL DEFAULT FALSE
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|||||||
+31
-14
@@ -23,13 +23,29 @@ def mainMenu():
|
|||||||
choice = input("Choose an option: ")
|
choice = input("Choose an option: ")
|
||||||
return choice
|
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):
|
def writeNew(db):
|
||||||
print("""
|
print("""
|
||||||
|
|
||||||
Write New Post
|
Write New Post
|
||||||
|
|
||||||
1. [N]ew Micropost
|
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: ")
|
choice = input("Choose an option: ")
|
||||||
@@ -40,6 +56,19 @@ def writeNew(db):
|
|||||||
confirmPost = input("Publish this micropost (Y/N)? ")
|
confirmPost = input("Publish this micropost (Y/N)? ")
|
||||||
if confirmPost == 'y' or confirmPost == 'Y':
|
if confirmPost == 'y' or confirmPost == 'Y':
|
||||||
bbdb.newPost(db, None, post)
|
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):
|
def editPost(db):
|
||||||
try:
|
try:
|
||||||
@@ -81,19 +110,7 @@ def editPost(db):
|
|||||||
else:
|
else:
|
||||||
print("Updated title.")
|
print("Updated title.")
|
||||||
elif choice == 'b' or choice == 'B' or choice == "2":
|
elif choice == 'b' or choice == 'B' or choice == "2":
|
||||||
editor = os.environ.get("EDITOR", os.environ.get("VISUAL", "vi"))
|
newBody = editText(post["body"])
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
print('Your new body text is:\n\n' + newBody + "\n")
|
print('Your new body text is:\n\n' + newBody + "\n")
|
||||||
confirmEdit = input("Publish this edited post [Y/N]? ")
|
confirmEdit = input("Publish this edited post [Y/N]? ")
|
||||||
if confirmEdit == 'y' or confirmEdit == 'Y':
|
if confirmEdit == 'y' or confirmEdit == 'Y':
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import markdown
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user