Started transfer function.

master
theissenm 3 years ago
parent c83497bbd3
commit 4507e3d6dd

@ -2,6 +2,29 @@
import sqlite3 import sqlite3
import os import os
clear = lambda: os.system('clear') clear = lambda: os.system('clear')
def transfer(a):
clear()
print()
connDb = sqlite3.connect(a)
cur = connDb.cursor()
userIn = input('Amount to transfer: $')
fromUser = input('From user: ')
toUser = input('To user: ')
fromId = cur.execute("SELECT id FROM account where username=?", (fromUser, )).fetchone()[0]
toId = cur.execute("SELECT id FROM account where username=?", (toUser, )).fetchone()[0]
prevFrom = cur.execute("SELECT balance from balance where id=?", (fromId, )).fetchone()[0]
prevTo = cur.execute("SELECT balance from balance where id=?", (toId, )).fetchone()[0]
#if prev
cur.execute("UPDATE balance SET balance=(?-?) WHERE id=?", (prevFrom, userIn, fromId, ))
cur.execute("UPDATE balance SET balance=(?+?) WHERE id=?", (prevTo, userIn, toId, ))
connDb.commit()
connDb.close()
clear()
print(f'Transfered ${userIn} from {fromUser} to {toUser}. ')
print()
manBankin(a)
def deposit(a): def deposit(a):
clear() clear()
print('Deposit: ') print('Deposit: ')
@ -37,7 +60,6 @@ def withdraw(a):
connDb.close() connDb.close()
def manBankin(a): def manBankin(a):
clear()
bankNam = a.split(".")[0] bankNam = a.split(".")[0]
print(f'Transactional menu for the {bankNam} bank. ') print(f'Transactional menu for the {bankNam} bank. ')
while True: while True:
@ -54,7 +76,7 @@ def manBankin(a):
elif userIn == "2": elif userIn == "2":
deposit(a) deposit(a)
elif userIn == "3": elif userIn == "3":
print("Transfer") transfer(a)
elif userIn == "4": elif userIn == "4":
print("User balance") print("User balance")
elif userIn == "9": elif userIn == "9":
@ -84,15 +106,14 @@ def deluser(a):
def listuser(a): def listuser(a):
connDb = sqlite3.connect(a) connDb = sqlite3.connect(a)
cur = connDb.cursor() cur = connDb.cursor()
userQuery = cur.execute("SELECT username FROM account;") userQuery = cur.execute("SELECT username FROM account;").fetchall()[0:]
userQuery = cur.fetchone()
connDb.close() connDb.close()
matchs = userQuery matchs = userQuery
print() print()
print("User list: ") print("User list: ")
print("__________________________") print("__________________________")
for i in matchs: for i in matchs:
print(i.split(".")[0]) print(i[0])
print("__________________________") print("__________________________")
def addUser(a): def addUser(a):
@ -168,7 +189,7 @@ def addBank():
TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP, ACTIVE BOOLEAN NOT NULL);''') TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP, ACTIVE BOOLEAN NOT NULL);''')
connDb.execute('''CREATE TABLE balance connDb.execute('''CREATE TABLE balance
(ID INTEGER PRIMARY KEY AUTOINCREMENT, (ID INTEGER PRIMARY KEY AUTOINCREMENT,
BALANCE INTEGER CHECK(BALANCE >= 0), BALANCE DOUBLE CHECK(BALANCE >= 0),
TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP);''') TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP);''')
connDb.execute('''CREATE TABLE banktrans connDb.execute('''CREATE TABLE banktrans
(ID INTEGER PRIMARY KEY, (ID INTEGER PRIMARY KEY,