#!/usr/bin/env python3 import sqlite3 import os def manageBankmenu(a): print(""" 1. Add a user. 2. Delete a user. 3. List users. 4. Banking Menu. Q to quit. """) while True: menuOption = input("Choose from the menu: ") if menuOption == '1': print('Add a user') elif menuOption == '2': print('delete a user') elif menuOption == '3': print('list users') elif menuOption == '4': print('banking menu') elif menuOption == 'q' or menuOption == 'Q': break else: print('*** Option not understood. Please try again.') def manageBank(): print() #connDb = sqlite3.connect() #cur = connDb.cursor() #cur.execute('SELECT username from ACCOUNT;') fmt = "{0}" #for row in cur.fetchall(): # print(fmt.format(*row)) print() def selectBank(): 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 = manBank+".db.sqlite" manageBankmenu(manBank) def addBank(): bankName = input("What would you like to call this bank? ") bankName = bankName+".db.sqlite" connDb = sqlite3.connect(bankName) connDb.execute('''CREATE TABLE ACCOUNT (ID INT PRIMARY KEY NOT NULL UNIQUE, USERNAME TEXT NOT NULL, TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP);''') connDb.execute('''CREATE TABLE BALANCE (ID INT PRIMARY KEY NOT NULL UNIQUE, BALANCE INT NOT NULL, TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP);''') connDb.execute('''CREATE TABLE BANKTRANS (ID INT PRIMARY KEY NOT NULL UNIQUE, USERNAME TEXT NOT NULL, TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP);''') connDb.close() os.system('clear') print() print(f'*** Added bank {bankName}') print() def listBank(): dirOutput = os.listdir() matchs = [match for match in dirOutput if 'db.sqlite' in match] print() print('Banks found: ') for i in matchs: print(i.split(".")[0]) while True: print(""" 1. Select a Bank. 2. Add new bank. 3. List banks. 4. Delete a bank. Q to quit. """) mainOption = input("Choose an option: ") if mainOption == '1': selectBank() elif mainOption == '2': addBank() elif mainOption == '3': listBank() elif mainOption == '4': print('Place function here.') elif mainOption == 'Q' or mainOption == 'q': break else: print() print('*** Option not understood. Please try again.')