|
|
@ -1,8 +1,25 @@
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sqlite3
|
|
|
|
import sqlite3
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
clear = lambda: os.system('clear')
|
|
|
|
|
|
|
|
def deposit(a):
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
print('Deposit: ')
|
|
|
|
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
|
|
|
|
cur = connDb.cursor()
|
|
|
|
|
|
|
|
withUser = input("User?: ")
|
|
|
|
|
|
|
|
userIn = int(input(f'{withUser}: Amount to deposit: '))
|
|
|
|
|
|
|
|
cur.execute("SELECT id FROM account where username=?", (withUser, ))
|
|
|
|
|
|
|
|
userId = cur.fetchone()[0]
|
|
|
|
|
|
|
|
cur.execute("SELECT balance from balance where id=?", (userId, ))
|
|
|
|
|
|
|
|
prevAmt = cur.fetchone()[0]
|
|
|
|
|
|
|
|
cur.execute("UPDATE balance SET balance=(?+?) WHERE id=?", (prevAmt, userIn, userId, ))
|
|
|
|
|
|
|
|
connDb.commit()
|
|
|
|
|
|
|
|
connDb.close()
|
|
|
|
|
|
|
|
|
|
|
|
def withdraw(a):
|
|
|
|
def withdraw(a):
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
print('Withdraw: ')
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
cur = connDb.cursor()
|
|
|
|
cur = connDb.cursor()
|
|
|
|
withUser = input("User?: ")
|
|
|
|
withUser = input("User?: ")
|
|
|
@ -20,36 +37,49 @@ def withdraw(a):
|
|
|
|
connDb.close()
|
|
|
|
connDb.close()
|
|
|
|
|
|
|
|
|
|
|
|
def manBankin(a):
|
|
|
|
def manBankin(a):
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
bankNam = a.split(".")[0]
|
|
|
|
|
|
|
|
print(f'Transactional menu for the {bankNam} bank. ')
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
bankNam = a.split(".")[0]
|
|
|
|
|
|
|
|
print("""
|
|
|
|
print("""
|
|
|
|
1. Withdraw
|
|
|
|
1. Withdraw
|
|
|
|
2. Deposit
|
|
|
|
2. Deposit
|
|
|
|
3. Transfer
|
|
|
|
3. Transfer
|
|
|
|
4. User Balance check
|
|
|
|
4. User Balance check
|
|
|
|
Q. Go Back
|
|
|
|
9. Go Back
|
|
|
|
""")
|
|
|
|
""")
|
|
|
|
userIn = input(f"Bank/{bankNam}: ")
|
|
|
|
userIn = input(f"Bank/{bankNam}: ")
|
|
|
|
if userIn == "1":
|
|
|
|
if userIn == "1":
|
|
|
|
withdraw(a)
|
|
|
|
withdraw(a)
|
|
|
|
elif userIn == "2":
|
|
|
|
elif userIn == "2":
|
|
|
|
print("Deposit")
|
|
|
|
deposit(a)
|
|
|
|
elif userIn == "3":
|
|
|
|
elif userIn == "3":
|
|
|
|
print("Transfer")
|
|
|
|
print("Transfer")
|
|
|
|
elif userIn == "4":
|
|
|
|
elif userIn == "4":
|
|
|
|
print("User balance")
|
|
|
|
print("User balance")
|
|
|
|
elif userIn == "q" or userIn == "Q":
|
|
|
|
elif userIn == "9":
|
|
|
|
break
|
|
|
|
manageBankmenu(a)
|
|
|
|
|
|
|
|
elif userIn == "8":
|
|
|
|
|
|
|
|
mainFunc()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print('*** Option not understood. Please try again.')
|
|
|
|
print('*** Option not understood. Please try again.')
|
|
|
|
|
|
|
|
|
|
|
|
def deluser(a):
|
|
|
|
def deluser(a):
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
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? ")
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
cur = connDb.cursor()
|
|
|
|
cur = connDb.cursor()
|
|
|
|
cur.execute("""UPDATE account SET active = 0 where username = ?""", (userIn,))
|
|
|
|
cur.execute("""UPDATE account SET active = 0 where username = ?""", (userIn,))
|
|
|
|
connDb.commit()
|
|
|
|
connDb.commit()
|
|
|
|
connDb.close()
|
|
|
|
connDb.close()
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
print(f'*** Deleted user {userIn} from bank {bankNam}. ')
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
print(f'You are managing the {bankNam} bank. ')
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
def listuser(a):
|
|
|
|
def listuser(a):
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
@ -66,6 +96,10 @@ def listuser(a):
|
|
|
|
print("__________________________")
|
|
|
|
print("__________________________")
|
|
|
|
|
|
|
|
|
|
|
|
def addUser(a):
|
|
|
|
def addUser(a):
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
bankNam = a.split(".")[0]
|
|
|
|
|
|
|
|
print(f'Add a user to bank {bankNam}. ')
|
|
|
|
|
|
|
|
print()
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
connDb = sqlite3.connect(a)
|
|
|
|
cur = connDb.cursor()
|
|
|
|
cur = connDb.cursor()
|
|
|
|
userIn = input('What user would you like to add? ')
|
|
|
|
userIn = input('What user would you like to add? ')
|
|
|
@ -74,15 +108,24 @@ def addUser(a):
|
|
|
|
cur.execute("INSERT INTO banktrans (username,amount) VALUES(?,0.00)", (userIn,))
|
|
|
|
cur.execute("INSERT INTO banktrans (username,amount) VALUES(?,0.00)", (userIn,))
|
|
|
|
connDb.commit()
|
|
|
|
connDb.commit()
|
|
|
|
connDb.close()
|
|
|
|
connDb.close()
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
print(f'*** Added user {userIn} to bank {bankNam}. ')
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
print(f"You are managing the {bankNam} bank. ")
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
def manageBankmenu(a):
|
|
|
|
def manageBankmenu(a):
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
bankNam = a.split(".")[0]
|
|
|
|
|
|
|
|
print(f'You are managing the {bankNam} bank. ')
|
|
|
|
|
|
|
|
print()
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
print("""
|
|
|
|
print("""
|
|
|
|
1. Add a user.
|
|
|
|
1. Add a user.
|
|
|
|
2. Delete a user.
|
|
|
|
2. Delete a user.
|
|
|
|
3. List users.
|
|
|
|
3. List users.
|
|
|
|
4. Banking Menu.
|
|
|
|
4. Banking Menu.
|
|
|
|
Q. Go Back.
|
|
|
|
9. Go Back.
|
|
|
|
""")
|
|
|
|
""")
|
|
|
|
menuOption = input("Bank: Choose from the menu: ")
|
|
|
|
menuOption = input("Bank: Choose from the menu: ")
|
|
|
|
if menuOption == '1':
|
|
|
|
if menuOption == '1':
|
|
|
@ -93,12 +136,15 @@ def manageBankmenu(a):
|
|
|
|
listuser(a)
|
|
|
|
listuser(a)
|
|
|
|
elif menuOption == '4':
|
|
|
|
elif menuOption == '4':
|
|
|
|
manBankin(a)
|
|
|
|
manBankin(a)
|
|
|
|
elif menuOption == 'q' or menuOption == 'Q':
|
|
|
|
elif menuOption == '9':
|
|
|
|
break
|
|
|
|
mainFunc()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print('*** Option not understood. Please try again.')
|
|
|
|
print('*** Option not understood. Please try again.')
|
|
|
|
|
|
|
|
|
|
|
|
def selectBank():
|
|
|
|
def selectBank():
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
print('Select a bank: ')
|
|
|
|
|
|
|
|
print()
|
|
|
|
dirOutput = os.listdir()
|
|
|
|
dirOutput = os.listdir()
|
|
|
|
matchs = [match for match in dirOutput if 'db.sqlite' in match]
|
|
|
|
matchs = [match for match in dirOutput if 'db.sqlite' in match]
|
|
|
|
#banks = dict(zip(matchs, range(len(matchs))))
|
|
|
|
#banks = dict(zip(matchs, range(len(matchs))))
|
|
|
@ -110,6 +156,9 @@ def selectBank():
|
|
|
|
manageBankmenu(manBank)
|
|
|
|
manageBankmenu(manBank)
|
|
|
|
|
|
|
|
|
|
|
|
def addBank():
|
|
|
|
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? ")
|
|
|
|
bankName = bankName+".db.sqlite"
|
|
|
|
bankName = bankName+".db.sqlite"
|
|
|
|
connDb = sqlite3.connect(bankName)
|
|
|
|
connDb = sqlite3.connect(bankName)
|
|
|
@ -127,12 +176,14 @@ def addBank():
|
|
|
|
AMOUNT INTEGER NOT NULL,
|
|
|
|
AMOUNT INTEGER NOT NULL,
|
|
|
|
TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP);''')
|
|
|
|
TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP);''')
|
|
|
|
connDb.close()
|
|
|
|
connDb.close()
|
|
|
|
os.system('clear')
|
|
|
|
clear()
|
|
|
|
print()
|
|
|
|
print()
|
|
|
|
print(f'*** Added bank {bankName}')
|
|
|
|
print(f'*** Added bank {bankName}')
|
|
|
|
print()
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
def listBank():
|
|
|
|
def listBank():
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
print()
|
|
|
|
dirOutput = os.listdir()
|
|
|
|
dirOutput = os.listdir()
|
|
|
|
matchs = [match for match in dirOutput if 'db.sqlite' in match]
|
|
|
|
matchs = [match for match in dirOutput if 'db.sqlite' in match]
|
|
|
|
print()
|
|
|
|
print()
|
|
|
@ -141,29 +192,31 @@ def listBank():
|
|
|
|
for i in matchs:
|
|
|
|
for i in matchs:
|
|
|
|
print(i.split(".")[0])
|
|
|
|
print(i.split(".")[0])
|
|
|
|
print("__________________________")
|
|
|
|
print("__________________________")
|
|
|
|
|
|
|
|
def mainFunc():
|
|
|
|
while True:
|
|
|
|
clear()
|
|
|
|
print("""
|
|
|
|
print('Welcome to the Kniod D&D Banking Software! ')
|
|
|
|
1. Select a Bank.
|
|
|
|
while True:
|
|
|
|
2. Add new bank.
|
|
|
|
print("""
|
|
|
|
3. List banks.
|
|
|
|
1. Select a Bank.
|
|
|
|
4. Delete a bank.
|
|
|
|
2. Add new bank.
|
|
|
|
Q to quit.
|
|
|
|
3. List banks.
|
|
|
|
""")
|
|
|
|
4. Delete a bank.
|
|
|
|
mainOption = input("Choose an option: ")
|
|
|
|
Q to quit.
|
|
|
|
if mainOption == '1':
|
|
|
|
""")
|
|
|
|
selectBank()
|
|
|
|
mainOption = input("Choose an option: ")
|
|
|
|
elif mainOption == '2':
|
|
|
|
if mainOption == '1':
|
|
|
|
addBank()
|
|
|
|
selectBank()
|
|
|
|
elif mainOption == '3':
|
|
|
|
elif mainOption == '2':
|
|
|
|
listBank()
|
|
|
|
addBank()
|
|
|
|
elif mainOption == '4':
|
|
|
|
elif mainOption == '3':
|
|
|
|
print('Place function here.')
|
|
|
|
listBank()
|
|
|
|
elif mainOption == 'Q' or mainOption == 'q':
|
|
|
|
elif mainOption == '4':
|
|
|
|
break
|
|
|
|
print('Place function here.')
|
|
|
|
else:
|
|
|
|
elif mainOption == 'Q' or mainOption == 'q':
|
|
|
|
print()
|
|
|
|
break
|
|
|
|
print('*** Option not understood. Please try again.')
|
|
|
|
else:
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
print('*** Option not understood. Please try again.')
|
|
|
|
|
|
|
|
mainFunc()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|