Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions Database/safe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import sqlite3
import base64
import imageio
Expand All @@ -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",
Expand All @@ -67,7 +70,7 @@
"py": "TEXT",
"jpg": "IMAGE",
"png": "IMAGE",
"jpeg": "IMAGE"
"jpeg": "IMAGE",
}

file_name = PATH.split("/")
Expand All @@ -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()
conn.commit()