Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ATM management System in Python #5181

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions Python Projects/ATM project/ATM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import os
import json
import datetime

current_directory = os.getcwd()
filename = "atmdb.json"
full_path = os.path.join(current_directory, filename)


class Method:
def __init__(self,user):
temp = []
with open(full_path, 'r') as f:
db = json.load(f)
for userCred in db :
if(userCred["userName"] != user["userName"]):
temp.append(userCred)
else:
temp.append(user)
with open(full_path, 'w') as fW:
json.dump(temp, fW, indent=4)

class UserLogin:
def __init__(self, userName, pin):
self.userName = userName
self.pin = pin

def checkCredentials(self):
with open(full_path, 'r') as f:
db = json.load(f)
for userCred in db:
if userCred["userName"] == self.userName:
if (userCred["pin"] == self.pin):
print("Login Successful")
return userCred
else:
print("Invalid Password")
exit()
else:
print("Invalid Credentials")
exit()


class TransactionsHistory:
def __init__(self, transactionHistory):
print("TRANSID\tTYPE\tAMOUNT\tDATE\tBALANCE")
for data in transactionHistory.get("transactions"):
print(f"{data['transID']}\t{data['type']}\t{data['amt']}\t{data['dateOfTrans']}\t{data['currentBal']}")


class Withdraw:
def __init__(self, amt,user):
newData = {}
currAmt = user["Balance"] - amt
newData["transID"] = 124578
newData["type"] = "debit"
newData["amt"] = amt
newData["dateOfTrans"] = f"{datetime.datetime.now()}"
newData["currentBal"] = currAmt
user["Balance"] = currAmt
user["transactions"].append(newData)
Method(user)
print("Data Saved Successfully!")




class Deposit:
def __init__(self, amt,user):
newData = {}
currAmt = user["Balance"] + amt
newData["transID"] = 124578
newData["type"] = "credit"
newData["amt"] = amt
newData["dateOfTrans"] = f"{datetime.datetime.now()}"
newData["currentBal"] = currAmt
user["Balance"] = currAmt
user["transactions"].append(newData)
Method(user)
print("Data Saved Successfully!")


class Transfer:
def __init__(self,user):
self.user = user
def sendMoney(self):
amt = int(input("Enter the amount: "))
upi = input("Enter UPI ID: ")
newData = {}
currAmt = user["Balance"] - amt
newData["transID"] = 124578
newData["upiID"] = upi
newData["type"] = "debit"
newData["amt"] = amt
newData["dateOfTrans"] = f"{datetime.datetime.now()}"
newData["currentBal"] = currAmt
user["Balance"] = currAmt
user["transactions"].append(newData)
Method(user)
print("Data Saved Successfully!")





# Driver's code
print("\n********** Welcome to our ATM **********")
userName = input("Enter your user ID: ")
pin = int(input("Enter your PIN : "))

userLogin = UserLogin(userName, pin)
user = userLogin.checkCredentials()
print("MENU List:- ")
print("\n[1]. View Transaction History\n[2]. Make a withdrawal \n[3]. Make deposit \n[4]. Transaction history \n[5]. Exit the program.\n")
while (True):
op = int(input("\nEnter your choice: "))
match(op):
case 1:
TransactionsHistory(user)
case 2:
amt = int(input("Enter the amount you want to withdraw: "))
Withdraw(amt,user)
case 3:
amt = int(input("Enter the amount you want to deposite: "))
Deposit(amt,user)
case 4:
Transfer(user).sendMoney()
case 5:
print("Thanks for using our ATM service.\n")
break
115 changes: 115 additions & 0 deletions Python Projects/ATM project/atmdb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[
{
"userName": "crazy",
"pin": 4444,
"Balance": 10000,
"transactions": [
{
"transID": 124536,
"type": "credit",
"amt": 1000,
"dateOfTrans": "2023-09-27 11:44:29.475018",
"currentBal": 10000
},
{
"transID": 124537,
"type": "debit",
"amt": 500,
"dateOfTrans": "2023-09-27 11:44:29.475018",
"currentBal": 9500
},
{
"transID": 124578,
"type": "debit",
"amt": 50,
"dateOfTrans": "2023-09-27 11:49:46.242608",
"currentBal": 9450
},
{
"transID": 124578,
"type": "debit",
"amt": 50,
"dateOfTrans": "2023-09-27 11:50:00.298747",
"currentBal": 9400
},
{
"transID": 124578,
"type": "debit",
"amt": 3,
"dateOfTrans": "2023-09-27 11:56:56.641310",
"currentBal": 9397
},
{
"transID": 124578,
"type": "debit",
"amt": 3,
"dateOfTrans": "2023-09-27 11:57:09.065439",
"currentBal": 9400
},
{
"transID": 124578,
"type": "debit",
"amt": 5,
"dateOfTrans": "2023-09-27 12:04:00.439480",
"currentBal": 9395
},
{
"transID": 124578,
"type": "credit",
"amt": 4,
"dateOfTrans": "2023-09-27 12:04:02.055387",
"currentBal": 9399
},
{
"transID": 124578,
"upiID": "soubhik",
"type": "debit",
"amt": 100,
"dateOfTrans": "2023-09-27 12:05:53.631628",
"currentBal": 9299
},
{
"transID": 124578,
"type": "debit",
"amt": 100,
"dateOfTrans": "2023-09-27 12:14:22.382354",
"currentBal": 9199
},
{
"transID": 124578,
"type": "debit",
"amt": 121,
"dateOfTrans": "2023-09-27 12:14:30.445988",
"currentBal": 9078
},
{
"transID": 124578,
"type": "debit",
"amt": 78,
"dateOfTrans": "2023-09-27 12:14:37.022460",
"currentBal": 9000
},
{
"transID": 124578,
"type": "credit",
"amt": 1000,
"dateOfTrans": "2023-09-27 12:14:45.614085",
"currentBal": 10000
}
]
},
{
"userName": "alpha",
"pin": 1234,
"Balance": 10000,
"transactions": [
{
"transID": 124536,
"type": "credit",
"amt": 1000,
"dateOfTrans": "2023-09-27 11:44:29.475018",
"currentBal": 10000
}
]
}
]