-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulateTransactions.py
139 lines (120 loc) · 3.5 KB
/
simulateTransactions.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
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
import requests
import json
import random
class Account:
def __init__(self, string):
quote = 0
self.message = ""
self.ID = ""
self.type = ""
self.nickname = ""
self.rewards = ""
self.balance = ""
self.accountNumber = ""
self.customerID = ""
while( self.ID == "" or self.type == "" or self.nickname == "" or self.rewards == "" or self.balance == "" or self.customerID == ""):
quote = string.find("\"",quote) + 1
tempType = string[quote: string.find("\"", quote)]
if tempType == "objectCreated":
quote = string.find("\"",quote) + 1
continue
elif tempType == "balance":
quote = string.find("\"",quote) + 1
tempData = string[quote+1:string.find(",",quote+1)]
#print(tempType + " " + tempData)
self.setVal(tempType,tempData)
continue
elif tempType == "rewards":
quote = string.find("\"",quote) + 1
tempData = string[quote+1:string.find(",",quote+1)]
self.setVal(tempType,tempData)
#print(tempType + " " + tempData)
continue
quote = string.find("\"",quote) + 1
quote = string.find("\"",quote) + 1
tempData = string[quote: string.find("\"",quote)]
#print(tempType + " " + tempData)
quote = string.find("\"", quote) + 1
self.setVal(tempType, tempData)
self.quoteRtn = quote
def setVal(self, dataType, data):
if(dataType == "message"):
self.message = data
elif(dataType == "_id"):
self.ID = data
elif(dataType == "nickname"):
self.nickname = data
elif(dataType == "rewards"):
self.rewards = data
elif(dataType == "balance"):
self.balance = data
elif(dataType == "account_number"):
self.accountNumber = data
elif(dataType == "customer_id"):
self.customerID = data
elif(dataType == "type"):
self.type = data
def used(self):
return self.quoteRtn
def getMessage(self):
return self.message
def getID(self):
return self.ID
def getNickname(self):
return self.nickname
def getRewards(self):
return self.rewards
def getBalance(self):
return self.balance
def getAccountNumber(self):
return self.accountNumber
def getCustomerID(self):
return self.customerID
print("Simulating transactions\n")
apiKey = 'fcdf2af0ab8427bcac93139bb0775400'
url = 'http://api.reimaginebanking.com/accounts?key={}'.format(apiKey)
accounts = requests.get(url)
accountStringtemp = ""
for string in accounts:
accountStringtemp = accountStringtemp + str(string)[2:]
accountString = accountStringtemp.replace("'", "")
accountDict = {}
idList = []
while len(accountString) > 10:
acc = Account(accountString)
accountDict[acc.getID()] = acc
idList.append(acc.getID())
accountString = accountString[acc.used():]
for j in range(20):
for i in range(len(idList)-1):
rand = random.randint(0,len(idList)-1);
while(i == rand):
rand = random.randint(0,len(idList)-1)
transfer = 100 * random.randint(1,5)
url = 'http://api.reimaginebanking.com/accounts/{}/transfers?key={}'.format(idList[i],apiKey)
# print(url)
body = {
"medium":"balance",
"payee_id":idList[rand],
"amount":transfer,
"transaction_date":"2016-11-" + str(j)
}
retval = requests.post(
url,
data=json.dumps(body),
headers={'content-type':'application/json'}
)
url = 'http://api.reimaginebanking.com/accounts/{}/transfers?key={}'.format(idList[len(idList)-1],apiKey)
rand = random.randint(0,len(idList)-1)
body = {
"medium":"balance",
"payee_id":idList[rand],
"amount":500,
"transaction_date":"2016-11-" + str(j)
}
retval = requests.post(
url,
data = json.dumps(body),
headers={'content-type':'application/json'},
)
#print (url)