I'm new to coding, and I'm self taught. recently, I made a sort of log database system using SQLite. I'm very proud that i got it to work, but I'm also looking for feedback. There's lots i don't know so I'm sure there's better ways for some things to be done. I'm thinking of adding a layered menu system with multiple nested loops or functions rather than having to cycle through the whole big one. That way someone can "go back" if they want to choose something else. All of the tags are by me for when i eventually look back at this to figure out wtf I did to make this work LOL. I also in the future want to figure out i there's a way to "clear" the console when executing this so once you're done reading or writing a log, it doesn't linger on the console screen while you do other things. There might be, but if there is a way to do that i haven't figured it out yet. (NOTE: I originally posted this in the wrong category, sorry!!
)
)import sqlite3
import datetime
def readlog(number):
for row in cur.execute("SELECT * FROM entry WHERE rowid = ?", [number]):
print(row)
con = sqlite3.connect("logsys.db")
cur = con.cursor()
cur.execute("SELECT name FROM sqlite_master WHERE type= 'table' AND name='entry'") #this is checking if the table already exists, then the if false statement runs code to make the table if it doesnt already exist
if False:
cur.execute("CREATE TABLE entry(day, words)")
res = cur.execute("SELECT name FROM sqlite_master WHERE name= 'spam'")
res.fetchone() is None
if True:
print(f"this code didnt find it, its working") #this is me checking that it queries correctly for the tables :)
#Now the table exists and we are connected. Before we actually start to make the entry, i think it would be good to make a 'menu' so we can nest the entry making into a loop.
def start():
while True:
print(f"Welcome to Beta Logs 2.0! You can either create a new log, or view the existing ones.")
print(f"To create a new log, type in 'create new log'")
print(f"to view the existing logs, type 'view logs'. They all have a number and date, and are in chronological order.")
print(f"If you with to exit, you can type 'exit'.")
menu = input("What can I help you with today?\n")
menu_2 = menu.lower()
if menu_2 == "create new log":
print(f"create new log query is working") #apparently the datetime thing is depreciated, so i have to figure out a way to input the day and time from the local computer using a sqlite alternative
content = input("Input Entry\n")
cur.execute("INSERT INTO entry (day, words) VALUES(CURRENT_DATE,?)", (content,))
con.commit()
elif menu_2 == "view logs":
print(f"view logs query is working")
for row in cur.execute("SELECT rowid, day FROM entry"):#this makes it so it shows all the logs but only with their row number and the date they were made on.
print(row)
number = input("Please enter the log number you would like to view.\n")
readlog(number)
input("To return to the menu, please press Enter.") #this leaves a gap so people can read before it boots them back
elif menu_2 == "delete logs":
decide = input("Are you sure?\n")
decide_2 = decide.lower()
if decide_2 == "yes":
print(f"Now deleting all logs...")
cur.execute("DELETE FROM entry")
con.commit()
print(f"Logs deleted.")
else:
print(f"Maybe next time...")
elif menu_2 == "exit":
print(f"Goodbye.")
con.close()
return
elif menu_2 == "secret":
password = input("Please enter password.\n")
pass_2 = password.lower()
if pass_2 == "password":
print(f"Really? Thats your guess?")
if pass_2 == "stegodandy":
print(f"A good guess, but sadly no.")
if pass_2 == "open sesame":
print(f"Close poppy seed.")
if pass_2 == "fartboy69":
print(f"Yes, this is the password. Yes, I do think im quite funny.\n")
print(f"For your prize for finding this, email me at [email protected]")
#i see you looking into the code to find the password...... well hey, you found it either way, i suppose...
else:
print(f"Incorrect Password.")
else:
print(f"Unknown query. Did you spell everything correctly?")
start()
exit()
