-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackaccount.py
More file actions
197 lines (140 loc) · 7.17 KB
/
Copy pathbackaccount.py
File metadata and controls
197 lines (140 loc) · 7.17 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
import os
import json
# Initial Directories
if not os.path.exists("Accounts"):
os.mkdir("Accounts")
# File Path Checking in Directory
def checking_file_exist(filepath):
print(filepath)
try:
os.path.exists(filepath)
except FileNotFoundError:
with open(f"{filepath}", "w") as f:
f.write("0")
# Account Creation
def account_generate(filepath, name, passcode=0000,):
account_info = {"bank" : "Sadaat Bank Limited", "name": name, "pass_code": passcode, "balance": 0, "history" : [] }
if os.path.exists(filepath):
print("You already Have Account, Login to your Account")
else:
os.mkdir(filepath)
print(f"Account Sucessfully Created")
with open(f"{filepath}/{name}_info.json", "w") as f:
json.dump(account_info, f)
# Account Verfication
def verify_account(name, passcode):
if os.path.exists(f"Accounts/{name}/{name}_info.json"):
with open(f"Accounts/{name}/{name}_info.json", "r") as f:
account_info = json.load(f)
if account_info["pass_code"] == passcode:
return True
else:
print("Invalid Passcode")
return False
else:
print(f"Hi {name}, You are not a Sadaat Bank Limited User.")
return False
class online_banking:
bankname = "Sadaat Bank Limited"
def __init__(self, name, balance=0):
self.account_holder = name
self.user_info_path = f"Accounts/{self.account_holder}/{self.account_holder}_info.json"
with open(self.user_info_path, "r") as f:
user_account_info = json.load(f)
self.balance = user_account_info["balance"]
print(f"Your Current Balance is {self.balance}")
with open(self.user_info_path, "r") as f:
account_info = json.load(f)
self.account_info = account_info
# Deposit Functionality
def deposit(self, amount):
self.balance += amount
self.account_info["balance"] = self.balance
with open(self.user_info_path, "w") as f:
self.account_info["history"].append(f"Welcome to {self.account_info["bank"]}, You Deposit Rupees +{amount}, You have Balance of Rupess {self.account_info["balance"]}")
json.dump(self.account_info, f , indent=4)
print(f"Welcome to {self.account_info["bank"]}, You Deposit Rupees: {amount} you balance is Rupees: {self.balance}")
# Withdrawal Functionality
def withdrawal(self, cash=0):
if cash <= self.balance and cash <= 50000:
self.balance -= cash
self.account_info["balance"] = self.balance
with open(f"{self.user_info_path}", "w") as f:
self.account_info["history"].append(f"Welcome to {self.account_info["bank"]}, You Widthawal of Rupees: {cash} you new balance is Rupees: {self.balance}")
json.dump(self.account_info, f , indent=4)
print(
f"Welcome to {self.account_info["bank"]}, You Widthawal of Rupees: {cash} you new balance is Rupees: {self.balance}")
elif cash > 50000:
print("You Limit is just 50,000 Rupess, Try lower Value")
else:
print("Insufficient Balance in your Account.")
# Balance Checker Functionality
def balance_check(self):
print(
f"Welcome to {self.account_info["bank"]}, Your account balance is {self.account_info["balance"]} ")
# Transaction History Functionality
def check_transaction_history(self):
for item in self.account_info["history"]:
print(f"{item}\n")
# Transfer Fund within Accounts Functionality
def transfer_fund(self, payee, value):
if payee != "" and value != "":
if value <= self.balance:
payee_path = f"Accounts/{payee}/{payee}_info.json"
if os.path.exists(payee_path):
with open(payee_path, "r") as f:
payee_info = json.load(f)
payee_balanace = payee_info["balance"]
self.balance -= value
payee_balanace += value
payee_info["balance"] = payee_balanace
self.account_info["balance"] = self.balance
with open(payee_path, "w") as f:
payee_info["history"].append(f"Welcome to {self.account_info["bank"]}, {self.account_holder} is transfered Rupees +{value}, You have Balance of Rupess {payee_info["balance"]}")
json.dump(payee_info, f , indent=4)
with open(self.user_info_path, "w") as f:
self.account_info["history"].append(f"Welcome to {self.account_info["bank"]}, {self.account_holder}, You Transfered -{value} Rupees to {payee}")
json.dump(self.account_info, f , indent=4)
print(
f"Welcome to {self.account_info["bank"]}, {self.account_holder}, You Transfered {value} Rupees to {payee}")
else:
print("Payee Account Not Available")
else:
print("Insufficient Balance in your Account")
# Selecting Actions Functionality
class account_handling:
type = input("Login / Signup: ")
def __init__(self):
self.account_user = input("Enter Name: ")
self.account_passcode = input("Enter Passcode: ")
self.account_path = f"Accounts/{self.account_user}"
if self.type == "Login":
if verify_account(self.account_user, self.account_passcode) is True:
account_access = online_banking(f"{self.account_user}")
print("Welcome to Sadaat Bank Limited!")
print("Withdraw\nDeposit\nBalance\nHistory\nTransfer\nLogout")
while True:
select_option = input("Select Menu: ").capitalize()
if select_option == "Deposit":
account_access.deposit(
int(input(f"{self.account_user} Deposit Amount: ")))
elif select_option == "Withdraw":
account_access.withdrawal(
int(input(f"{self.account_user} Withdraw Amount: ")))
elif select_option == "Balance":
account_access.balance_check()
elif select_option == "History":
account_access.check_transaction_history()
elif select_option == "Transfer":
account_access.transfer_fund(
input("Enter Payee Name: "), int(input("Enter Amount: ")))
elif select_option == "Logout":
print(f"Thank you to using the Standard Chartered Bank, Bye Bye")
break
else:
print(
f"Your Selected Option {select_option} is not available in menu")
if self.type == "Signup":
account_generate(self.account_path,
self.account_user, self.account_passcode)
start_banking = account_handling()