-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.py
More file actions
467 lines (437 loc) · 21 KB
/
Copy pathBank.py
File metadata and controls
467 lines (437 loc) · 21 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
from datetime import datetime
import pandas
import os
import random
import string
account_numbers_list=[]
class Validation:
def __init__(self):
self.first_name=""
self.last_name=""
self.phone=""
self.birthday=""
self.nationalcode=""
self.inventory=""
self.email=""
self.account_num=""
#Validation of name (must be letter)
def validation_name(self):
while (True):
for character in self.first_name:
if character not in string.ascii_letters :
print( "Error\n!!!You are not allowed to use characters <<!/@^%#@*()!1-9,...>> in this field!!!")
self.first_name=input("Name again:")
break
else:
return True
#Validation of last name (must be letter)
def validation_lastname(self):
while(True):
for chracters in self.last_name:
if chracters not in string.ascii_letters:
print( "Error\n!!!You are not allowed to use characters <<!/@^%#@*()!1-9,...>> in this field!!!")
self.last_name=input("Name again:")
break
else:
return True
#Validation of Phone (must be statred with "09" and has 11 chracters)
def validation_Phone(self):
while (True):
if len(self.phone)!=9:
print("Error\n!!! length phone is invalid !!!")
self.phone=input("Phone again:09")
for character in self.phone:
if character not in string.digits:
print("Error\n!!! Your phone is invalid !!!")
self.phone=input("Phone again:09")
break
else:
return True
#Validation of date (must be like: 1900-12-30)
def validation_date(self):
while(True):
try:
datetime.strptime(self.birthday,"%Y-%m-%d")
return True
except:
print("Error\n!!! Your date of birthday is invalid !!!")
self.birthday=input("Birthday again:")
break
# must be int and not be Empty
def validation_inventory(self):
while(True):
if not self.inventory.isdigit():
print("Error\n!!! Your inventory is invalid you just enter number !!!")
self.inventory=input("inventory again:")
continue
else:
self.inventory=int(self.inventory)
return True
#Validation of Nationalcode
def validation_nationalcode(self):
while (True):
if len(self.nationalcode)!=9:
print("Error\n!!! length nationalcode is invalid !!!")
self.nationalcode=input("National Code again:0")
for character in self.nationalcode:
if character not in string.digits:
print("Error\n!!! Your NationalCode has invalid characters!!!\njust use number")
self.nationalcode=input("National Code again:0")
break
else:
return True
#Validation of email
# 1)Email should have @ and .
# 2)Email should have a @ just once
# 3)Email should have a . in domain (gmail.com)
# 4)Email should have a something before and after @ and couldn't be empty.
# 5)Email should have domain for gmail(just gamil.com)
def validation_email(self):
while(True):
if "@" not in self.email or "." not in self.email:
print("Error\n!!! Your Email is invalid !!!")
self.email=input("Email again:").lower()
continue
if self.email.count("@")!=1:
print("Error\n!!! Your Email is invalid \n You can not use to <@> more than onece!!!")
self.email=input("Email again:").lower()
continue
if self.email.split("@")[0]=="" or self.email.split("@")[1]=="":
print("Error\n!!! Your Email is invalid \n You must enter something after or befor <@>!!!")
self.email=input("Email again:").lower()
continue
if "." not in self.email.split("@")[1] or "" in self.email.split("@")[1].split("."):
print("Error\n!!! Your Email is invalid \n You must use to < . > in domain name !!!")
self.email=input("Email again:").lower()
continue
if self.email.split("@")[1] !="gmail.com":
print("Error\n!!! Your Email is invalid \n not incorrect <gmail.com> !!!")
self.email=input("Email again:").lower()
continue
return True
# Making Account numbers
def validation_accountnumber(self):
while(True):
temp=''
try:
for i in range(int(self.account_num)):
temp+=str(random.randint(0,9))
if temp not in account_numbers_list:
account_numbers_list.append(temp)
print(f"make the account number sucssesfully! ---------> {temp}")
break
else:
print("this account number was exise in\npls wait make another...")
continue
except:
print("Error ! just enter number")
self.account_num=input("length Account Number again (default=16):")
continue
class SaveToExcel:
def __init__(self, excel_file=r"Bank.xlsx", text_file=r"Bank.txt"):
# path_=os.getcwd()
# self.text_file=path_ + "/Bank.txt"
# self.excel_file=path_ + "/Bank.xlsx"
path_=os.path.dirname(os.path.abspath(__file__))
self.text_file=os.path.join(path_,"Bank.txt")
self.excel_file=os.path.join(path_,"Bank.xlsx")
if not os.path.exists(self.excel_file):
dataformat=pandas.DataFrame(columns=["First Name","Last Name","Phone","Birthday","NationalCode","Inventory","Email","Account Number"])
dataformat.to_excel(self.excel_file, index=False)
if not os.path.exists(self.text_file):
open(self.text_file,"w").close()
def save_to_text(self, first_name, last_name, phone, birthday, nationalcode, inventory, email, account_num):
with open(self.text_file, "a", encoding="utf-8") as txt:
txt.write(f"{first_name}\t{last_name}\t{phone}\t{birthday}\t{nationalcode}\t{inventory}\t{email}\t{account_num}\n")
print("Adding user Succesfully!")
def save_to_excel(self):
datas=pandas.read_csv(self.text_file, sep="\t", header=None, names=["First Name","Last Name","Phone","Birthday","NationalCode","Inventory","Email","Account Number"], dtype=str)
if os.path.exists(self.excel_file):
before_data=pandas.read_excel(self.excel_file)
if ((before_data["First Name"]==datas["First Name"][0])&(before_data["Last Name"]==datas["Last Name"][0])).any():
print("user exists")
datas=pandas.concat([before_data,datas], ignore_index=True)
datas["Phone"]="09"+datas["Phone"].astype(str)
datas["NationalCode"]="0"+datas["NationalCode"].astype(str)
datas["Account Number"]=""+datas["Account Number"].astype(str)
datas.to_excel(self.excel_file, index=False)
print("Saved to Excel Succesfully!")
def final_save_excel(self, first_name, last_name, phone, birthday, nationalcode, inventory, email, account_num):
data_read=pandas.read_excel(self.excel_file, dtype=str)
if ((data_read["First Name"]==first_name)&(data_read["Last Name"]==last_name)&(data_read["Phone"]==phone)).any():
print("______ERROR______\nUser exists")
return
self.save_to_text(first_name, last_name, phone, birthday, nationalcode, inventory, email, account_num)
self.save_to_excel()
valid=Validation()
saving_excel=SaveToExcel()
class User:
def __init__(self, first_name="", last_name="", phone="", birthday="", nationalcode="", inventory="", email="", account_num=""):
self.first_name=first_name
self.last_name=last_name
self.phone=phone
self.birthday=birthday
self.nationalcode=nationalcode
self.inventory=inventory
self.email=email
self.account_num=account_num
#1
def creat_user(self):
valid.first_name=input("Name:")
valid.validation_name()
valid.last_name=input("Last Name:")
valid.validation_lastname()
valid.phone=input("Phone:09")
valid.validation_Phone()
valid.birthday=input("Birthday (Like this:1900-12-30):")
valid.validation_date()
valid.nationalcode=input("National Code:0")
valid.validation_nationalcode()
valid.inventory=input("Inventory:")
valid.validation_inventory()
valid.email=input("Email:").lower()
valid.validation_email()
valid.account_num=input("length Account Number (default=16):")
valid.validation_accountnumber()
saving_excel.final_save_excel(valid.first_name,
valid.last_name,
valid.phone,
valid.birthday,
valid.nationalcode,
valid.inventory,
valid.email,
account_numbers_list[-1]
)
exit("__________DONE__________")
#2
def deposit_account(self):
deposit_src=input("Enter account number:").strip()
path_=os.path.dirname(os.path.abspath(__file__))
excel_file=os.path.join(path_,"Bank.xlsx")
if not os.path.exists(excel_file):
print("__ERROR___\nYOU FIRST MAKE ACCOUNT!")
return
data=pandas.read_excel(excel_file,dtype=str)
source=data[data['Account Number']==deposit_src]
get_amount=None
try:
get_amount=int(input(f"How much do you put into \n{str(source["First Name"].values[0])}\n{str(source["Last Name"].values[0])}\n{str(source["Account Number"].values[0])}\n:"))
except:
print("Error!\nNot found it\nFirst crean account")
return
if get_amount>0 and int(source["Inventory"].values[0])>=get_amount:
result_src=data[data['Account Number']==deposit_src]
try:
inventory_src=int(result_src['Inventory'].values[0])
except:
print("Error!")
nvt_caculate_src=inventory_src+get_amount
data=pandas.read_excel(excel_file,dtype=str)
data['Inventory']=data['Inventory'].astype(int)
src_index=data.index[data['Account Number']==deposit_src][0]
data.at[src_index, 'Inventory']=nvt_caculate_src
data.to_excel(excel_file, index=False)
print("_______________CONGRATULATIONS________________\n____________Money deposit completed successfully_____________\n_________________Inventory update successfully________________")
print(f"to {str(source["First Name"].values[0])} {str(source["Last Name"].values[0])} with {str(source["Account Number"].values[0])} with {get_amount}$")
#3
def withdarawal_account(self):
deposit_src=input("Enter account number:").strip()
path_=os.path.dirname(os.path.abspath(__file__))
excel_file=os.path.join(path_,"Bank.xlsx")
if not os.path.exists(excel_file):
print("__ERROR___\nYOU FIRST MAKE ACCOUNT!")
return
data=pandas.read_excel(excel_file,dtype=str)
source=data[data['Account Number']==deposit_src]
get_amount=None
try:
get_amount=int(input(f"How much do you put into \n{str(source["First Name"].values[0])}\n{str(source["Last Name"].values[0])}\n{str(source["Account Number"].values[0])}\n:"))
except:
print("Error!\nNot found it\nFirst crean account")
return
if get_amount>0 and int(source["Inventory"].values[0])>=get_amount :
result_src=data[data['Account Number']==deposit_src]
try:
inventory_src=int(result_src['Inventory'].values[0])
except:
print("Error!")
nvt_caculate_src=inventory_src-get_amount
if nvt_caculate_src>=0:
data=pandas.read_excel(excel_file,dtype=str)
data['Inventory']=data['Inventory'].astype(int)
src_index=data.index[data['Account Number']==deposit_src][0]
data.at[src_index, 'Inventory']=nvt_caculate_src
data.to_excel(excel_file, index=False)
print("_______________CONGRATULATIONS________________\n____________Money withdrawal completed successfully_____________\n_________________Inventory update successfully________________")
print(f"{str(source["First Name"].values[0])} {str(source["Last Name"].values[0])} with {str(source["Account Number"].values[0])} withdraval {get_amount}$")
else:
print("Not enough inventory")
#4
def edit_info_account(self):
deposit_src=input("Enter account number:").strip()
path_=os.path.dirname(os.path.abspath(__file__))
excel_file=os.path.join(path_,"Bank.xlsx")
if not os.path.exists(excel_file):
print("__ERROR___\nYOU FIRST MAKE ACCOUNT!")
return
data=pandas.read_excel(excel_file,dtype=str)
if deposit_src not in data["Account Number"].values:
print("this account number not found")
return
src_index=data.index[data['Account Number']==deposit_src][0]
while True:
print("which field you want to change it?\n1)first name\n2)last name\n3)phone\n4)birthday\n5)nationalcode\n6)Email\n")
try:
get_=int(input("pls Enter number(1-6):"))
except:
print("ERROR!\njust enter number")
return
if get_==1:
valid.first_name=input("pls enter new name:")
valid.validation_name()
data.at[src_index,"First Name"]=valid.first_name
elif get_==2:
valid.last_name=input("pls enter new last name:")
valid.validation_lastname()
data.at[src_index,"Last Name"]=valid.last_name
elif get_==3:
valid.phone=input("pls enter new phone:09")
valid.validation_Phone()
data.at[src_index,"Phone"]="09"+str(valid.phone)
elif get_==4:
valid.birthday=input("pls enter new Birthday:")
valid.validation_date()
data.at[src_index,"Birthday"]=valid.birthday
elif get_==5:
valid.nationalcode=input("pls enter new nationalcode:0")
valid.validation_nationalcode()
data.at[src_index,"NationalCode"]="0"+valid.nationalcode
elif get_==6:
valid.email=input("pls enter new email:")
valid.validation_email()
data.at[src_index,"Email"]=valid.email
print("_____________________Edited successfully_________________________")
data.to_excel(excel_file, index=False)
#5
def show_money(self):
deposit_src=input("Enter account number to see value of money:").strip()
path_=os.path.dirname(os.path.abspath(__file__))
excel_file=os.path.join(path_,"Bank.xlsx")
if not os.path.exists(excel_file):
print("__ERROR___\nYOU FIRST MAKE ACCOUNT!")
return
try:
data=pandas.read_excel(excel_file,dtype=str)
except:
print("Error!")
return
try:
source=data[data['Account Number']==deposit_src]
except:
print("Error!")
return
try:
inventory_src=int(source['Inventory'].values[0])
except:
print("Error!")
return
print("_____________________________Total value money____________________________")
print(f"{ source['First Name'].values[0]} {source['Last Name'].values[0]} =========> {inventory_src}$")
#6
def transfer_money(self, excel_file=r"Bank.xlsx"):
path_=os.path.dirname(os.path.abspath(__file__))
path_excel=os.path.join(path_,"Bank.xlsx")
data=pandas.read_excel(path_excel, dtype=str)
while True:
deposit_src=input("Source account number:").strip()
source=data[data['Account Number']==deposit_src]
if source.empty :
print("Error!\n not found source in excel!")
continue
print("______FOUND ACCOUNT_______")
print(source)
try:
get_user=int(input("<<<CONFIRM INFORMATION>>>\n 1)Next\t 2)Cancel\t=>"))
except:
print("ERROR!")
continue
if get_user==1:
print("_____next____")
break
elif get_user==2:
exit("____EXIT____")
return
else:
print("JUST ENTER NUM 1/2")
continue
while True:
deposit_dst=input("Destination account number:").strip()
destination=data[data['Account Number']==deposit_dst]
if destination.empty :
print("Error!\n not found destination in excel!")
continue
print("______FOUND ACCOUNT_______")
print(destination)
try:
get_user_=int(input("<<<CONFIRM INFORMATION>>>\n 1)Next\t 2)Cancel\t=>"))
except:
print("ERROR!")
continue
if get_user_==1:
print("_____next____")
get_amount=int(input(f"How much do you put into \n{str(destination["First Name"].values[0])}\n{str(destination["Last Name"].values[0])}\n{str(destination["Account Number"].values[0])}\n:"))
if get_amount>0 and int(source["Inventory"].values[0])>=get_amount:
path_=os.path.dirname(os.path.abspath(__file__))
excel_file=os.path.join(path_,"Bank.xlsx")
if not os.path.exists(excel_file):
print("__ERROR___\nYOU FIRST MAKE ACCOUNT!")
return
data=pandas.read_excel(excel_file,dtype=str)
result_src=data[data['Account Number']==deposit_src]
result_dst=data[data['Account Number']==deposit_dst]
try:
inventory_src=int(result_src['Inventory'].values[0])
inventory_dst=int(result_dst['Inventory'].values[0])
except:
print("Error!")
nvt_caculate_src=inventory_src-get_amount
nvt_caculate_dst=inventory_dst+get_amount
data=pandas.read_excel(excel_file,dtype=str)
data['Inventory']=data['Inventory'].astype(int)
src_index=data.index[data['Account Number']==deposit_src][0]
dst_index=data.index[data["Account Number"]==deposit_dst][0]
data.at[src_index, 'Inventory']=nvt_caculate_src
data.at[dst_index, 'Inventory']=nvt_caculate_dst
data.to_excel(excel_file, index=False)
print("_______________CONGRATULATIONS________________\n____________Money transfer completed successfully_____________\n_________________Inventory update successfully________________")
print(f"FROM {str(source["First Name"].values[0])} {str(source["Last Name"].values[0])} with {str(source["Account Number"].values[0])}----------TO------------{str(destination["First Name"].values[0])} {str(destination["Last Name"].values[0])} with {str(destination["Account Number"].values[0])}")
else:
print("You can't make the payment")
break
elif get_user_==2:
exit("____EXIT____")
return
else:
print("JUST ENTER NUM 1/2")
continue
def Home_page():
user_bank=User()
print("___________________WELCOME_______________________")
print("1)Creat an account\n2)Deposit to the account\n3)Withdraw from the account\n4)Change account details\n5)View account balance\n6)Transfer to another person's account")
try:
choice=int(input("Enter your choices (1-6):"))
except:
print("Error!\njust enter number")
if choice==1:
user_bank.creat_user()
elif choice==2:
user_bank.deposit_account()
elif choice==3:
user_bank.withdarawal_account()
elif choice==4:
user_bank.edit_info_account()
elif choice==5:
user_bank.show_money()
elif choice==6:
user_bank.transfer_money()
Home_page()