-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
103 lines (89 loc) · 3.99 KB
/
functions.py
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
import random
import requests
from pymongo import MongoClient
def bankuser(data):
# client = pymongo.MongoClient("mongodb://127.0.0.1:27017/")
# client = pymongo.MongoClient("mongodb+srv://ajinkya:[email protected]/test")
client = MongoClient("mongodb+srv://test:[email protected]/myFirstDatabase?retryWrites=true&w=majority",connect=False)
db = client["bankdata"]
collection = db["userinfo"]
data["accNo"]= " ".join([str(random.randint(0,999)).zfill(3) for _ in range(2)])
data ["balance"] = 0
__pipeline__ = [
{
'$project':{
'_id': 0,
'accNo': 1
}
}
]
acc_list = list(collection.aggregate(__pipeline__))
acc_list = [i['accNo'] for i in acc_list]
if data['accNo'] in acc_list:
data['accNo'] = ' '.join([str(random.randint(0, 999)).zfill(3) for _ in range(2)])
collection.insert_one(data)
else:
collection.insert_one(data)
return f"You have registered successfully and your account number is {data['accNo']} "
def bank_balance(accNo):
# client = pymongo.MongoClient("mongodb://127.0.0.1:27017/")
# client = pymongo.MongoClient("mongodb+srv://ajinkya:[email protected]/test")
client = MongoClient("mongodb+srv://test:[email protected]/myFirstDatabase?retryWrites=true&w=majority",connect=False)
db = client["bankdata"]
collection = db["userinfo"]
__pieline__ = [
{
'$match':{
'accNo':accNo['accNo']
}
}
]
acc_data = list(collection.aggregate(__pieline__))
if len(acc_data)!=1:
return "Please check your account number"
else:
return f" Your balance is {acc_data[0]['balance']}"
def withdrawl(data):
# client = pymongo.MongoClient("mongodb://127.0.0.1:27017/")
# client = pymongo.MongoClient("mongodb+srv://ajinkya:[email protected]/test")
client = MongoClient("mongodb+srv://test:[email protected]/myFirstDatabase?retryWrites=true&w=majority",connect=False)
db = client["bankdata"]
collection = db["userinfo"]
__pieline__ = [
{
'$match': {
'accNo': data['accNo']
}
}
]
acc_data = list(collection.aggregate(__pieline__))
if len(acc_data)!=1:
return "Please check your account number"
elif int(data['withdraw_bal']) > int(acc_data[0]['balance']):
return "Your balance is insufficient"
else:
balance = acc_data[0]['balance']
update = int(balance) - int(data['withdraw_bal'])
collection.update_one({'accNo':data['accNo']},{'$set':{'balance': update}})
return f" Your withrawal is successful and remaining balance is {update}"
def deposit(data):
# client = pymongo.MongoClient("mongodb://127.0.0.1:27017/")
# client = pymongo.MongoClient("mongodb+srv://ajinkya:[email protected]/test")
client = MongoClient("mongodb+srv://test:[email protected]/myFirstDatabase?retryWrites=true&w=majority",connect=False)
db = client["bankdata"]
collection = db["userinfo"]
__pieline__ = [
{
'$match': {
'accNo': data['accNo']
}
}
]
acc_data = list(collection.aggregate(__pieline__))
if len(acc_data)!=1:
return "Please check your account number"
else:
balance = acc_data[0]['balance']
update = int(balance) + int(data['deposit_amt'])
collection.update_one({'accNo':data['accNo']},{'$set':{'balance':update}})
return f"Your deposit is successful and current balance is {update}"