From c3eae98f1dd518c6601ce696fbc958dcf7541fdc Mon Sep 17 00:00:00 2001 From: Soubhik Banerjee <90599826+soubhik-111@users.noreply.github.com> Date: Sun, 1 Oct 2023 05:13:00 +0530 Subject: [PATCH] Add files via upload --- Python Projects/ATM project/ATM.py | 130 +++++++++++++++++++++++++ Python Projects/ATM project/atmdb.json | 115 ++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 Python Projects/ATM project/ATM.py create mode 100644 Python Projects/ATM project/atmdb.json diff --git a/Python Projects/ATM project/ATM.py b/Python Projects/ATM project/ATM.py new file mode 100644 index 0000000000..b9a2e63ab5 --- /dev/null +++ b/Python Projects/ATM project/ATM.py @@ -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 diff --git a/Python Projects/ATM project/atmdb.json b/Python Projects/ATM project/atmdb.json new file mode 100644 index 0000000000..25d2230881 --- /dev/null +++ b/Python Projects/ATM project/atmdb.json @@ -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 + } + ] + } +] \ No newline at end of file