1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import json
- import os
- def writeTrans(sender, recipient, amount):
- bcDir = os.curdir + '/Trans/'
- files = os.listdir(bcDir)
- files = sorted([int(i) for i in files])
- lastFile = files[-1]
- fileName = str(lastFile + 1)
- data = {'sender': sender,
- 'recipient': recipient,
- 'amount': amount
- }
- if sender == 'bank':
- score = 0
- with open('bank', 'r') as file:
- text = json.load(file)
- score = float(text["score"]) - amount
- with open('bank', 'w') as file:
- json.dump({'score': score}, file, indent=4)
- if recipient == 'bank':
- score = 0
- with open('bank', 'r') as file:
- text = json.load(file)
- score = float(text["score"]) + amount
- with open('bank', 'w') as file:
- json.dump({'score': score}, file, indent=4)
- if sender == 'agency':
- score = 0
- with open('agency', 'r') as file:
- text = json.load(file)
- score = float(text["score"]) - amount
- with open('agency', 'w') as file:
- json.dump({'score': score}, file, indent=4)
- if recipient == 'agency':
- score = 0
- with open('agency', 'r') as file:
- text = json.load(file)
- score = float(text["score"]) + amount
- with open('agency', 'w') as file:
- json.dump({'score': score}, file, indent=4)
-
- with open(bcDir + fileName, 'w') as file:
- json.dump(data, file, indent=4)
- def writeDriver(fullName, number, deadline, category, exp, numbersac, fines, premium, balance):
- bcDir = os.curdir + '/drivers/'
- files = os.listdir(bcDir)
- files = sorted([int(i) for i in files])
- lastFile = files[-1]
- fileName = str(lastFile + 1)
- data = {'fullName': fullName,
- 'cardNumber': number,
- 'cardDeadline': deadline,
- 'category': category,
- 'exp': exp,
- 'number of accidents': numbersac,
- 'fines': fines,
- 'premium': premium,
- 'balance': balance
- }
- with open(bcDir + fileName, 'w') as file:
- json.dump(data, file, indent=4)
- def checkBank():
- with open('bank', 'r') as file:
- text = json.load(file)
- score = float(text["score"])
- return score
|