-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM.py
257 lines (167 loc) · 6.08 KB
/
ATM.py
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
#GLOBAL
from datetime import time
from os import P_NOWAIT
import random
import time
from datetime import datetime
from getpass import getpass
import validation
import database
now = datetime.now()
currentDate = now.strftime("%d-%B-%Y")
currentTime = now.strftime("%I : %M %p")
userdatabasepath = "userRecord/"
def generateAccountNumber ():
return random.randrange(1111111111,9999999999)
def initalization():
print("Welcome to the BANK OF JP".center(10, '*').upper())
print("""
Do you have an account with us ?
1. Yes
2. No
""")
try:
ownAccount = int(input("Enter your option>>> "))
except ValueError:
return initalization()
if (ownAccount == 1):
return login()
elif(ownAccount == 2):
return registeration()
else:
print("You have selected invalid option")
return initalization()
def login():
print("***************Login to your new account***************")
userAccountNumber = input("Enter your account number \n")
isLoginNumberValidation = validation.loginNumberValidation(userAccountNumber)
if isLoginNumberValidation:
# password = input("Enter your password\n")
password = getpass("Enter your password\n")
user = database.authenticateUser(userAccountNumber, password)
if user:
print("Login successful\n\n")
time.sleep(1.0)
print(f'====WELCOME to JP BANK '.upper())
# importing date and time
print("Today's date is == :", currentDate)
print("Your time is ==", currentTime)
print("********************************")
print("********************************")
return bankingOperation(userAccountNumber)
else:
print('\nInvalid account or password')
return login()
else:
print("Account Number Invalid: check that you have up to 10 digits and only integer")
return login()
def registeration():
print('=== REGISTER BELOW ===')
email = input("Enter your email address\t\n")
firstName = input("Enter your first name\t\n")
lastName = input("Enter your last name\t\n")
password = getpass("Enter your password\n")
accountNumber = generateAccountNumber()
balance = 500
isUserCreated = database.create(accountNumber, firstName, lastName, email, password, balance)
if isUserCreated:
print(f"{firstName} Your account creation is successfull\n")
print(" ====== ====== ====== ====== =====")
print(f'Your account number is {accountNumber}\n')
print("Keep your account number safe ")
login()
else:
print("Something went wrong, please try agian")
registeration()
def bankingOperation(accountNumber):
user = database.read(accountNumber)
print(f"Welcome {user[0]} {user[1]}".title())
print(""" What will you want to do
1. Deposit
2. Withdrawal
3. Complaint
4. Balance
5. Logout
""")
optionSelected = int(input(">> "))
if(optionSelected == 1):
return depositOperation(accountNumber)
elif(optionSelected == 2):
return withdrawalOperation(accountNumber)
elif(optionSelected == 3):
return complaintOperation (accountNumber)
elif (optionSelected == 4):
return getCurrentBalance(accountNumber)
elif (optionSelected == 5):
return logout(accountNumber)
else:
print("Invalid option selected")
return bankingOperation(accountNumber)
def withdrawalOperation(accountNumber):
action = 'withdraw'
withdraw_amount = input("Enter Amount to Withdraw>\t#")
is_valid = validation.validateInput(withdraw_amount)
if not is_valid:
return withdrawalOperation(accountNumber)
else:
bal = database.update(accountNumber, action , withdraw_amount)
if bal:
print("Please take your cash.")
return again(accountNumber)
def depositOperation(accountNumber):
action = 'deposit'
deposit_amount = input("Enter Amount to Deposit>\t#")
is_valid = validation.validateInput(deposit_amount)
if not is_valid:
return depositOperation(accountNumber)
else:
bal = database.update(accountNumber, action , deposit_amount)
if bal:
print("Deposit successful")
return again(accountNumber)
def again(accountNumber):
try:
again = int(input("Do you want to perform another action?\n\t1. Yes\n\t2. No \n\n >"))
if again == 1:
return bankingOperation(accountNumber)
elif again == 2:
return logout(accountNumber)
else:
print("Invalid input")
except ValueError:
print("Enter 1 or 2.")
return logout(user="")
def getCurrentBalance(accountNumber):
balance = int(database.read(accountNumber)[-1])
print(f"Your current balance is:\t #{balance}\n\n")
return again(accountNumber)
def complaintOperation(accountNumber):
print("What issue will you like to report")
print("********************************")
complaint = input("Enter your complaint\n")
# database2 = [Complaint] for
print(" Thank you for contacting us, your comment has been received by us")
print("********************************")
return again(accountNumber)
def logout(user):
print(f'Do you want to exit?')
print(f'If Yes press 1 or No press 2')
try:
exitoption = int(input('>> '))
time.sleep(0.5)
except ValueError:
print("You have made an invalid selection. Try again\n")
return exit()
try:
if exitoption == 1:
print("We will love to see you back")
exit()
elif exitoption == 2:
return bankingOperation(user)
else:
return logout(user)
except ValueError:
print('Invalid Selection. Try again')
return logout(user)
############### SYSTEM INITIALIZATION ###################
initalization()