Now checks for valid banks names

master
Matt Theissen 3 years ago
parent 64f425e8c8
commit 2be6a56249

@ -6,8 +6,15 @@ clear = lambda: os.system('clear')
def return_31(wrgUser,a):
clear()
print(f"31: User {wrgUser} not found. Select menu 3 to see a complete list of users.")
print()
manageBankmenu(a)
def return_37(a):
clear()
print(f"37: Bank {a} not found. ")
print()
mainFunc()
def userCheck(use,a):
connDb = sqlite3.connect(a)
cur = connDb.cursor()
@ -20,19 +27,25 @@ def userCheck(use,a):
if userCheck.usrtst != "pass":
return_31(use,a)
def checkBank(a):
dirOutput = os.listdir()
matchs = [match for match in dirOutput if 'db.sqlite' in match]
for i in matchs:
checkBank.bnktst = 'fail'
if a == i.split(".")[0]:
checkBank.bnktst = 'pass'
if checkBank.bnktst != "pass":
return_37(a)
def transfer(a):
clear()
print()
connDb = sqlite3.connect(a)
cur = connDb.cursor()
userIn = input('Amount to transfer: $')
fromUser = input('From user: ')
# userQuery = cur.execute("SELECT username FROM account;").fetchall()[0:]
# matchs = userQuery
# if userIn != for i in matchs:
# print(i[0])
userIn = input('Amount to transfer: $').lower()
fromUser = input('From user: ').lower()
userCheck(fromUser,a)
toUser = input('To user: ')
toUser = input('To user: ').lower()
userCheck(toUser,a)
fromId = cur.execute("SELECT id FROM account where username=?", (fromUser, )).fetchone()[0]
toId = cur.execute("SELECT id FROM account where username=?", (toUser, )).fetchone()[0]
@ -55,9 +68,10 @@ def deposit(a):
print('Deposit: ')
connDb = sqlite3.connect(a)
cur = connDb.cursor()
withUser = input("User?: ")
userIn = input(f'{withUser}: Amount to deposit: ')
cur.execute("SELECT id FROM account where username=?", (withUser, ))
depUser = input("User?: ").lower()
userCheck(depUser,a)
userIn = input(f'{depUser}: Amount to deposit: ').lower()
cur.execute("SELECT id FROM account where username=?", (depUser, ))
userId = cur.fetchone()[0]
cur.execute("SELECT balance from balance1 where id=?", (userId, ))
prevAmt = cur.fetchone()[0]
@ -69,8 +83,9 @@ def withdraw(a):
print('Withdraw: ')
connDb = sqlite3.connect(a)
cur = connDb.cursor()
withUser = input("User?: ")
userIn = input(f'{withUser}: Amount to withdraw: ')
withUser = input("User?: ").lower()
userCheck(withUser,a)
userIn = input(f'{withUser}: Amount to withdraw: ').lower()
cur.execute("SELECT id FROM account where username=?", (withUser, ))
userId = cur.fetchone()[0]
cur.execute("SELECT balance from balance1 where id=?", (userId, ))
@ -94,7 +109,7 @@ def manBankin(a):
4. User Balance check
9. Go Back
""")
userIn = input(f"Bank/{bankNam}: ")
userIn = input(f"Bank/{bankNam}: ").lower()
if userIn == "1":
withdraw(a)
elif userIn == "2":
@ -115,7 +130,7 @@ def deluser(a):
bankNam = a.split(".")[0]
print(f'Delete a user from bank {bankNam}. ')
print()
userIn = input("Which user would you like to delete? ")
userIn = input("Which user would you like to delete? ").lower()
connDb = sqlite3.connect(a)
cur = connDb.cursor()
cur.execute("""UPDATE account SET active = 0 where username = ?""", (userIn,))
@ -147,7 +162,7 @@ def addUser(a):
print()
connDb = sqlite3.connect(a)
cur = connDb.cursor()
userIn = input('What user would you like to add? ')
userIn = input('What user would you like to add? ').lower()
cur.execute("INSERT INTO account (username,active) VALUES(?,1)", (userIn,))
cur.execute("INSERT INTO balance1 (balance) VALUES(0)")
cur.execute("INSERT INTO balance2 (balance) VALUES(0)")
@ -162,6 +177,7 @@ def addUser(a):
def manageBankmenu(a):
bankNam = a.split(".")[0]
print()
print(f'You are managing the {bankNam} bank. ')
print()
while True:
@ -172,7 +188,7 @@ def manageBankmenu(a):
4. Banking Menu.
9. Go Back.
""")
menuOption = input("Bank: Choose from the menu: ")
menuOption = input("Bank: Choose from the menu: ").lower()
if menuOption == '1':
addUser(a)
elif menuOption == '2':
@ -192,19 +208,20 @@ def selectBank():
print()
dirOutput = os.listdir()
matchs = [match for match in dirOutput if 'db.sqlite' in match]
#banks = dict(zip(matchs, range(len(matchs))))
for i in matchs:
print(i.split(".")[0])
print()
manBank = input('Choose which bank you would like to manage: ')
manBank = input('Choose which bank you would like to manage: ').lower()
checkBank(manBank)
manBank = manBank+".db.sqlite"
clear()
manageBankmenu(manBank)
def addBank():
clear()
print('Add a bank: ')
print()
bankName = input("What would you like to call this bank? ")
bankName = input("What would you like to call this bank? ").lower()
bankName = bankName+".db.sqlite"
connDb = sqlite3.connect(bankName)
connDb.execute('''CREATE TABLE account
@ -241,8 +258,25 @@ def listBank():
for i in matchs:
print(i.split(".")[0])
print("__________________________")
print()
def delBank():
listBank()
delIn = input('Which bank would you like to delete? ').lower()
checkBank(delIn)
delIn = delIn + '.db.sqlite'
confIn = input(f'Confirm you want to delete bank {delIn}? [y/N] ').lower()
if confIn == 'n' or confIn == "":
clear()
mainFunc()
elif confIn == 'y':
cmd = 'rm {0}'.format(delIn)
os.system(cmd)
clear()
print(f'Bank {delBank} has been deleted.')
print()
def mainFunc():
clear()
print('Welcome to the Kniod D&D Banking Software! ')
while True:
print("""
@ -252,20 +286,16 @@ def mainFunc():
4. Delete a bank.
Q to quit.
""")
mainOption = input("Choose an option: ")
if mainOption == '1':
clear()
mainOption = int(input("Choose an option: "))
if mainOption == 1:
selectBank()
elif mainOption == '2':
clear()
elif mainOption == 2:
addBank()
elif mainOption == '3':
clear()
elif mainOption == 3:
listBank()
elif mainOption == '4':
clear()
print('Place function here.')
elif mainOption == 'Q' or mainOption == 'q':
elif mainOption == 4:
delBank()
elif mainOption == 'Q':
exit()
else: