validation of user input in replies

This commit is contained in:
cmccabe 2019-12-08 11:40:25 +00:00
parent ac4a97fd43
commit e7b4c0d4dd
1 changed files with 19 additions and 13 deletions

View File

@ -252,22 +252,28 @@ def reply(owner, tstamp, post_id):
comment = input("Enter your comment (or leave empty to abort): ")
if comment == "":
input("Reply aborted. Hit [Enter] to continue.")
else:
if os.path.exists(config.USER.datafile):
append_write = "a" # append if already exists
while True:
if comment == "":
input("Reply aborted. Hit [Enter] to continue.")
break
elif not posts.is_valid(comment):
print("Please try again, that response contains invalid characters.")
comment = posts.rlinput("Enter your comment (or leave empty to abort):")
else:
append_write = "w+" # make a new file if not
with open(config.USER.datafile, append_write) as file:
timestamp = str(time.time())
file.write(timestamp + "|" + owner + "+" + tstamp + "|||" + comment + "\n")
if os.path.exists(config.USER.datafile):
append_write = "a" # append if already exists
else:
append_write = "w+" # make a new file if not
with open(config.USER.datafile, append_write) as file:
timestamp = str(time.time())
file.write(timestamp + "|" + owner + "+" + tstamp + "|||" + comment + "\n")
link_data.insert(
0, ["", username, timestamp, owner + "+" + tstamp, "", "", comment]
)
link_data.insert(
0, ["", username, timestamp, owner + "+" + tstamp, "", "", comment]
)
input("Reply added. Hit [Enter] to return to thread.")
input("Reply added. Hit [Enter] to return to thread.")
break
view_thread(post_id)