Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
Fixed bugs, added minimalStyle, added checkboxes.
  • Loading branch information
AvgBlank authored Jul 29, 2023
1 parent 4108f67 commit c01f30e
Showing 1 changed file with 62 additions and 45 deletions.
107 changes: 62 additions & 45 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def encryption():
ClearScreen()

while True:
inp = confirm("Do you have an encryption key?").ask()
inp = confirm("Do you have an encryption key?", style=minimalStyle).ask()
if inp:
key = password("Enter the key:").ask()
key = password("Enter the key:", style=minimalStyle).ask()
elif inp == False:
while True:
GenKey = confirm(
"Do you want to generate a key?\n[You will lose access to previous data]"
"Do you want to generate a key?\n[You will lose access to previous data]",
style=minimalStyle,
).ask()
if GenKey == False:
exit()
Expand All @@ -74,7 +75,9 @@ def encryption():
f"Given below is the key, you will not get access to it again.\n{key}"
)
while True:
copyKey = confirm("Do you want to copy the key?").ask()
copyKey = confirm(
"Do you want to copy the key?", style=minimalStyle
).ask()
if copyKey:
pyperclip.copy(key)
break
Expand All @@ -89,8 +92,26 @@ def encryption():

######? Clear Screen #####
def ClearScreen():
global minimalStyle
#####* For Rich #####
console = Console()

#####* For Questionary Style #####
minimalStyle = Style(
[
("answer", "fg:#FFFFFF italic"), # ? White
("question", "fg:#FFFFFF bold"), # ? White
("pointer", "fg:#00FFFF bold"), # ? Cyan
("highlighted", "fg:#FFFFFF"), # ? White
("selected", "fg:#A9A9A9"), # ? Grey
("qmark", "fg:#77DD77"), # ? Green
]
)

#####* Clearing the Screen #####
system("clear" if OSName == "posix" else "cls")

#####* Printing Password Manager #####
console.print(Panel.fit("[bold italic #77DDD4]Password Manager", padding=(0, 22)))


Expand All @@ -111,11 +132,15 @@ def StatBar(time: float, desc: str):
def GenPass(p):
genop = ""
while True:
gen = confirm("Do you want to generate a password?").ask()
gen = confirm("Do you want to generate a password?", style=minimalStyle).ask()
if gen:
while True:
try:
genlen = int(text("How long should the password be?").ask())
genlen = int(
text(
"How long should the password be?", style=minimalStyle
).ask()
)
if genlen <= 0:
raise ValueError
break
Expand Down Expand Up @@ -158,16 +183,18 @@ def AddEntry(t):

#####* Getting Values #####
while True:
name = text("What do you want the entry to be called?").ask()
name = text(
"What do you want the entry to be called?", style=minimalStyle
).ask()
if name == "":
print("Name cannot be left empty.")
continue
if name.lower() in NameResult:
print("That name already exists.")
continue
break
email = text("Enter Email ID [Optional]:").ask()
usrname = text("Enter Username [Optional]:")
email = text("Enter Email ID [Optional]:", style=minimalStyle).ask()
usrname = text("Enter Username [Optional]:", style=minimalStyle).ask()
passwd = GenPass("Enter Password:")
passwd = fernet.encrypt(passwd.encode())

Expand Down Expand Up @@ -205,41 +232,41 @@ def EditEntry(t):
for i in result:
options.append(f"{i[0]}. {i[1]}".title())
options.append("0. Back")
choice = select("Which entry do you want to edit?", options).ask()
choice = select(
"Which entry do you want to edit?", options, style=minimalStyle
).ask()
choice = int(choice[0])
if choice == 0:
raise AttributeError

#####* Getting Values #####
opt = checkbox("What all do you want to edit?", ["Name", "Email", "Username", "Password"]).ask()
opt = checkbox(
"What all do you want to edit?",
["Name", "Email", "Username", "Password"],
style=minimalStyle,
).ask()
###? Name ###
if "Name" in opt:
while True:
Name = text("What should the name be?").ask()
Name = text("What should the name be?", style=minimalStyle).ask()
if Name == "":
print("Name cannot be left empty.")
continue
cur.execute(rf"update {t} set Name='{Name}' where IndexNo={choice}")
break
###? Email ###
if "Email" in opt:
Email = text("What should the email be?").ask()
cur.execute(
rf"update {t} set Email='{Email}' where IndexNo={choice}"
)
Email = text("What should the email be?", style=minimalStyle).ask()
cur.execute(rf"update {t} set Email='{Email}' where IndexNo={choice}")
###? Username ###
if "Username" in opt:
Username = text("What should the username be?").ask()
cur.execute(
rf"update {t} set Username='{Username}' where IndexNo={choice}"
)
Username = text("What should the username be?", style=minimalStyle).ask()
cur.execute(rf"update {t} set Username='{Username}' where IndexNo={choice}")
###? Password ###
if "Password" in opt:
Passwd = GenPass("What should the password be?")
Passwd = fernet.encrypt(Passwd.encode())
cur.execute(
rf'update {t} set Password="{Passwd}" where IndexNo={choice}'
)
cur.execute(rf'update {t} set Password="{Passwd}" where IndexNo={choice}')
if Name == "-" and Email == "-" and Username == "-" and Passwd == "-":
print("The entry has not been modified.")
else:
Expand Down Expand Up @@ -277,7 +304,9 @@ def DelEntry(t):
for i in result:
options.append(f"{i[0]}. {i[1]}".title())
options.append("0. Back")
choice = select("Which entry do you want to edit?", options).ask()
choice = select(
"Which entry do you want to edit?", options, style=minimalStyle
).ask()
choice = int(choice[0])
if choice == 0:
raise AttributeError
Expand All @@ -287,7 +316,8 @@ def DelEntry(t):
cur.execute(rf"select Name from {t} where IndexNo={choice}")
name = cur.fetchall()[0][0]
conf = confirm(
f"Are you sure you want to delete the entry for {name}?"
f"Are you sure you want to delete the entry for {name}?",
style=minimalStyle,
).ask()
if conf:
cur.execute(rf"delete from {t} where IndexNo={choice}")
Expand All @@ -304,7 +334,7 @@ def DelEntry(t):
conn.commit()
###? Confirmation ###
print(f"The entry for {name} has been successfully deleted!")
sleep(1)
input("Please enter to continue...")
break
elif conf == False:
break
Expand Down Expand Up @@ -351,13 +381,11 @@ def CopyEntry(t):
name = cur.fetchall()[0][0]
while True:
###? Getting What User Wants to Copy to Clipboard ###
conf = (
select(
"What do you want to copy?",
["Email", "Username", "Password"],
)
.ask()
)
conf = select(
"What do you want to copy?",
["Email", "Username", "Password"],
style=minimalStyle,
).ask()
###? Email ###
if conf == "Email":
cur.execute(rf"select Email from {t} where IndexNo={choice}")
Expand Down Expand Up @@ -415,24 +443,13 @@ def PrintOptions():
while True:
global minimalStyle

#####* For Questionary Style #####
minimalStyle = Style(
[
("answer", "fg:#FFFFFF italic"), # ? White
("question", "fg:#FFFFFF bold"), # ? White
("pointer", "fg:#00FFFF bold"), # ? Cyan
("highlighted", "fg:#FFFFFF"), # ? White
("selected", "fg:#A9A9A9"), # ? Grey
("qmark", "fg:#77DD77"), # ? Green
]
)

####* Clearing the Screen ####
ClearScreen()
####* Printing Options ####
choice = select(
"What is your choice?",
["Add Entry", "Edit Entry", "Delete Entry", "Copy Entry", "Quit"],
style=minimalStyle,
).ask()

#######? Calling Functions #######
Expand Down

0 comments on commit c01f30e

Please sign in to comment.