-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp_a_t.py
More file actions
305 lines (256 loc) · 9.52 KB
/
p_a_t.py
File metadata and controls
305 lines (256 loc) · 9.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import time
import os
import sqlite3
import random
from datetime import datetime
conn = sqlite3.connect("mydatabase.db")
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Bank_Log(
Time DATETIME NOT NULL,
Sender VARCHAR(20) NOT NULL,
Receiver VARCHAR(20) NOT NULL,
Amount FLOAT(2) NOT NULL,
Sender_Balance Float(2) NOT NULL,
Receiver_Balance FLOAT(2) NOT NULL
);
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS Bank_Database(
Account_Number INTEGER PRIMARY KEY,
User_Name VARCHAR(20) NOT NULL,
Age INTEGER NOT NULL,
Type CHAR(1) NOT NULL,
Phone INTEGER NOT NULL UNIQUE,
Email VARCHAR(30) NOT NULL UNIQUE,
Login_Name VARCHAR(20) NOT NULL UNIQUE,
User_Password VARCHAR(20) NOT NULL,
Balance FLOAT(2) NOT NULL
);
''')
def accnum_creation():
while 1:
r = random.randint(0000000000,9999999999)
query = "select Account_Number from Bank_Database where Account_Number = ?"
c = list(cursor.execute(query,(r,)))
if not c:
break
return r
def AccountCreate():
try:
acc = accnum_creation()
name = input("Name: ")
age = int(input("Age: "))
type = input("Type(s/c): ")
email = input("Email: ")
phone = input("Phone: ")
username = input("Username: ")
password = input("password: ")
cpassword = input("confirm password: ")
bal = 0.00
if password!=cpassword:
print("password doesn't match with confirm password")
time.sleep(3)
clear()
AccountCreate()
if len(phone)!=10:
raise
cursor.execute('''
insert into Bank_Database(Account_Number,User_Name,Age,Type,Phone,
Email,Login_Name,User_Password,Balance) values ({},'{}',{},'{}',{},'{}','{}','{}',{})
'''.format(acc,name,age,type,int(phone),email,username,cpassword,bal))
conn.commit()
print("Account creation Successfull")
time.sleep(3)
except Exception as e:
print("Invalid credentials Try again...")
time.sleep(5)
clear()
os.system("python p_a_t.py")
else:
clear()
print("login page\n")
login()
def TakeInput2():
print("[0] NO")
print("[1] YES")
return input(">>>")
def clear():
os.system("cls")
def menu(acc):
print("[1] Transfer Money")
print("[2] Deposit Money")
print("[3] Print Statement")
print("[0] Exit")
inp = input(">>>")
if inp == '1':
clear()
transfer(acc)
elif inp=='2':
clear()
deposit(acc)
elif inp=='3':
clear()
statement(acc)
elif inp=='0':
print("thank you for banking with us....\nHave a nice day!!!")
time.sleep(3)
exit()
def login():
try:
username = input("Username: ")
password = input("Password: ")
query = "select Login_Name from Bank_Database where Login_Name = ?"
cursor.execute(query,(username,))
usr =cursor.fetchone()
if usr:
query1 = "select User_Password from Bank_Database where Login_Name = ?"
cursor.execute(query1,(username,))
ps = cursor.fetchone()
if ps[0]==password:
print("\nLogin Successful !!!")
query2 = "select Account_Number from Bank_Database where Login_Name = ?"
cursor.execute(query2,(username,))
acc = (cursor.fetchone())[0]
time.sleep(2)
else:
raise
else:
raise
except Exception as e:
print("Inavalid Credentials...")
time.sleep(5)
clear()
login()
else:
menu(acc)
def deposit(acc):
amount = float(input("Amount: "))
cnf_amount = float(input("Confirm Amount: "))
if cnf_amount!=amount:
print("account doesn't match")
clear()
time.sleep(2)
deposit()
cursor.execute("select Balance from Bank_Database where Account_Number = ?",(acc,))
bal = cursor.fetchone()
new_bal = bal[0]+amount
cursor.execute("update Bank_Database set Balance = {} where Account_Number = {}".format(new_bal,acc))
now = datetime.now()
qry = '''
insert into Bank_Log(Time,Sender,Receiver,Amount,Sender_Balance,Receiver_Balance)
values(?,?,?,?,?,?)'''
cursor.execute(qry,(now.strftime("%Y-%m-%d %H:%M:%S"),acc,acc,amount,new_bal,new_bal))
conn.commit()
print("Amount deposited successfully!!")
with open(f'{acc}.txt','a+') as fp:
fp.write(f"{now} \t {amount} \t\t {new_bal}\n")
menu(acc)
def transfer(acc):
ben_name = input("Enter benificary Name: ")
ben_acc = int(input("Enter benificary account num: "))
cben_acc = int(input("confirm account num: "))
money = float(input("enter money to be transfered: "))
if ben_acc!=cben_acc:
print("account num & confirm account num doesn't match")
time.sleep(2)
clear()
transfer()
if ben_name==acc:
print("can't transfer to own bank account")
time.sleep(2)
clear()
transfer()
print("Are the details correct, Confirm again..")
x = TakeInput2()
if x=='0':
clear()
transfer(acc)
elif x=='1':
query1 = '''
select User_Name,Account_Number from Bank_Database
where User_Name = ? and Account_Number = ?
'''
if cursor.execute(query1,(ben_name,ben_acc)):
cursor.execute("select Balance from Bank_Database where Account_Number = ?",(ben_acc,))
bal_ben = cursor.fetchone()
new_bal_ben = bal_ben[0]+money
cursor.execute("select Balance from Bank_Database where Account_Number = ?",(acc,))
bal_sen = cursor.fetchone()
new_bal_sen = bal_sen[0]-money
if new_bal_sen < 0.00:
print("Amount exceeded to transfer than the actual balance")
time.sleep(3)
transfer(acc)
cursor.execute("update Bank_Database set Balance = {} where Account_Number = ? ".format(new_bal_ben),(ben_acc,))
cursor.execute("update Bank_Database set Balance = {} where Account_Number = ? ".format(new_bal_sen),(acc,))
conn.commit()
print("Money credited to the beneficeary")
time.sleep(5)
now = datetime.now()
qry = '''
insert into Bank_Log(Time,Sender,Receiver,Amount,Sender_Balance,Receiver_Balance)
values(?,?,?,?,?,?)'''
cursor.execute(qry,(now.strftime("%Y-%m-%d %H:%M:%S"),acc,ben_acc,money,new_bal_sen,new_bal_ben))
conn.commit()
with open(f'{ben_acc}.txt','a+') as fp:
fp.write(f"{now} \t {money} \t\t {new_bal_ben}\n")
with open(f'{acc}.txt','a+') as fp:
fp.write(f"{now} \t -{money} \t\t {new_bal_sen}\n")
menu(acc)
else:
print("Invalid credentials....Try again")
time.sleep(5)
transfer(acc)
def statement(acc):
with open(f"{acc}.txt",'r+') as fp:
line = fp.readlines()
clear()
print(" DateTime Transaction Current_balance\n")
if len(line)==0:
print("statement is empty")
for i in line:
print(i)
try:
print('\n\n')
if input("press [0] to exit to menu: ")=='0':
menu(acc)
except Exception as e:
print("Some error occured Try again...")
clear()
os.system("python p_a_t.py")
if __name__ == "__main__":
print("*****************************************************************************")
print('''
/$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$
/$$__ $$| $$__ $$ /$$__ $$ | $$__ $$ /$$__ $$| $$$ | $$| $$ /$$/
| $$ \ $$| $$ \ $$| $$ \__/ | $$ \ $$| $$ \ $$| $$$$| $$| $$ /$$/
| $$$$$$$$| $$$$$$$ | $$ | $$$$$$$ | $$$$$$$$| $$ $$ $$| $$$$$/
| $$__ $$| $$__ $$| $$ | $$__ $$| $$__ $$| $$ $$$$| $$ $$
| $$ | $$| $$ \ $$| $$ $$ | $$ \ $$| $$ | $$| $$\ $$$| $$\ $$
| $$ | $$| $$$$$$$/| $$$$$$/ | $$$$$$$/| $$ | $$| $$ \ $$| $$ \ $$
|__/ |__/|_______/ \______/ |_______/ |__/ |__/|__/ \__/|__/ \__/
''')
print("*****************************************************************************\n")
print("Existing Customer?")
inp = TakeInput2()
if inp == '0':
clear()
print("\nWe are delighted to have you here \nWould you like to create a account with us?\n")
inp = TakeInput2()
if inp=='0':
clear()
print("If anything else we can do for you you can you can contact at our nearest branch")
print("the system will exit in 5 seconds")
print("thank you for coming here, have a nice day")
time.sleep(5)
exit()
elif inp=='1':
clear()
AccountCreate()
elif inp=='1':
clear()
login()
else:
clear()
os.system("python p_a_t.py")