From b9fc9dd1c7dfcc1f0776077cc57c8bc8b07e0d1b Mon Sep 17 00:00:00 2001 From: sayampradhan <112542130+sayampradhan@users.noreply.github.com> Date: Fri, 14 Oct 2022 23:43:15 +0530 Subject: [PATCH] Format Code --- Database/safe.py | 54 ++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/Database/safe.py b/Database/safe.py index 6fc706b..9e97e95 100644 --- a/Database/safe.py +++ b/Database/safe.py @@ -1,4 +1,3 @@ - import sqlite3 import base64 import imageio @@ -15,50 +14,54 @@ break if connect == PASSWORD: - conn = sqlite3.connect('mysafe.db') + conn = sqlite3.connect("mysafe.db") try: - conn.execute('''CREATE TABLE SAFE + conn.execute( + """CREATE TABLE SAFE (FULL_NAME TEXT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, EXTENSION TEXT NOT NULL, - FILES TEXT NOT NULL);''') + FILES TEXT NOT NULL);""" + ) print("Your safe has been created!\nWhat would you like to store in it today?") except: print("You have a safe, what would you like to do today?") - - + while True: - print("\n"+ "*"*15) + print("\n" + "*" * 15) print("Commands:") print("q = quit program") print("o = open file") print("s = store file") - print("*"*15) + print("*" * 15) input_ = raw_input(":") if input_ == "q": break if input_ == "o": # open the file - file_type = raw_input("What is the filetype of the file you want to open?\n") + file_type = raw_input( + "What is the filetype of the file you want to open?\n" + ) file_name = raw_input("What is the name of the file you want to open?\n") FILE_ = file_name + "." + file_type - cursor = conn.execute("SELECT * from SAFE WHERE FULL_NAME=" + '"' + FILE_ + '"') + cursor = conn.execute( + "SELECT * from SAFE WHERE FULL_NAME=" + '"' + FILE_ + '"' + ) file_string = "" for row in cursor: file_string = row[3] - with open(FILE_, 'wb') as f_output: + with open(FILE_, "wb") as f_output: print(file_string) f_output.write(base64.b64decode(file_string)) - - - if input_ == "s": # store file - PATH = raw_input("Type in the full path to the file you want to store.\nExample: /Users/kalle/Desktop/myfile.py\n") + PATH = raw_input( + "Type in the full path to the file you want to store.\nExample: /Users/kalle/Desktop/myfile.py\n" + ) FILE_TYPES = { "txt": "TEXT", @@ -67,7 +70,7 @@ "py": "TEXT", "jpg": "IMAGE", "png": "IMAGE", - "jpeg": "IMAGE" + "jpeg": "IMAGE", } file_name = PATH.split("/") @@ -82,18 +85,25 @@ except: Exception() - if EXTENSION == "IMAGE": IMAGE = cv2.imread(PATH) - file_string = base64.b64encode(cv2.imencode('.jpg', IMAGE)[1]).decode() + file_string = base64.b64encode(cv2.imencode(".jpg", IMAGE)[1]).decode() elif EXTENSION == "TEXT": file_string = open(PATH, "r").read() file_string = base64.b64encode(file_string) EXTENSION = file_name.split(".")[1] - - command = 'INSERT INTO SAFE (FULL_NAME, NAME, EXTENSION, FILES) VALUES (%s, %s, %s, %s);' %('"' + file_name +'"', '"' + NAME +'"', '"' + EXTENSION +'"', '"' + file_string +'"') - + + command = ( + "INSERT INTO SAFE (FULL_NAME, NAME, EXTENSION, FILES) VALUES (%s, %s, %s, %s);" + % ( + '"' + file_name + '"', + '"' + NAME + '"', + '"' + EXTENSION + '"', + '"' + file_string + '"', + ) + ) + conn.execute(command) - conn.commit() \ No newline at end of file + conn.commit()