-
Notifications
You must be signed in to change notification settings - Fork 1
/
smsTypes.py
executable file
·260 lines (236 loc) · 7.44 KB
/
smsTypes.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
class basicSms:
def __init__(self):
self.type = "none"
self.newBal = 0
self.day = 0
self.month = 0
self.year = 0
def setType(self,type):
self.type=type
def setNewBal(self,bal):
self.newBal=bal
def setDay(self,day):
self.day=day
def setMonth(self,month):
self.month=month
def setYear(self,year):
self.year=year
#get methods
def getType(self):
return self.type
def getNewBal(self):
return self.newBal
def getDay(self):
return self.day
def getMonth(self):
return self.month
def getYear(self):
return self.year
class sndCash(basicSms):
def setAmt(self,amt):
self.amt=amt
def setName(self,name):
self.receiverName=name
def setCost(self,cost):
self.cost=cost
#get methods
def getAmt(self):
return self.amt
def getName(self):
return self.receiverName
def getCost(self):
return self.cost
class buyAirtm(basicSms):
def setAmt(self,amt):
self.amt=amt
def getAmt(self):
return self.amt
class withdraw(basicSms):
def setAmt(self,amt):
self.amt=amt
def getAmt(self):
return self.amt
class deposit(basicSms):
def setAmt(self,amt):
self.amt=amt
def getAmt(self):
return self.amt
class receive(basicSms):
def setAmt(self,amt):
self.amt=amt
def setSender(self,name):
self.name=name
#get methods
def getAmt(self):
return self.amt
def getSender(self):
return self.name
class inquiry(basicSms):
def getCost(self):
return self.cost
def getAmt(self):
return self.amt
def setCost(self,cost):
self.cost=cost
def setAmt(self,amt):
self.amt=amt
class bill(basicSms):
def getEntity(self):
return self.entity
def getAmt(self):
return self.amt
def setEntity(self,entity):
self.entity=entity
def setAmt(self,amt):
self.amt=amt
def parse(type,instance,msgSp):
if type==1:#send cash object
instance.setType("SND")#set the type
amount=currencyFormat(msgSp[2])
instance.setAmt(amount)#set amount sent
receiver=msgSp[5]+" "+msgSp[6]
instance.setName(receiver)
for i in xrange(len(msgSp)):
if(msgSp[i].find("on")!=-1):
dateIdx=(i+1)
dateList=msgSp[dateIdx]
dateList=dateList.split("/")
instance.setDay(int(dateList[0]))
instance.setMonth(int(dateList[1]))
instance.setYear(int(dateList[2]))
for i in xrange(len(msgSp)):
if(msgSp[i].find("balance")!=-1):
balIdx=(i+2)
bal=currencyFormat(msgSp[balIdx])
instance.setNewBal(bal)#set new Balance
elif type==2:#receive cash object
instance.setType("REC")
received=currencyFormat(msgSp[5])
instance.setAmt(received)#set received cash amount
sender=msgSp[7]+" "+msgSp[8]
instance.setSender(sender)#set sender details
for i in xrange(len(msgSp)):
if(msgSp[i].find("balance")!=-1):
balIdx=(i+2)
bal=currencyFormat(msgSp[balIdx])
instance.setNewBal(bal)#set new Balance
for i in xrange(len(msgSp)):
if(msgSp[i].find("on")!=-1):
dateIdx=(i+1)
dateList=msgSp[dateIdx]
dateList=dateList.split("/")
instance.setDay(int(dateList[0]))
instance.setMonth(int(dateList[1]))
instance.setYear(int(dateList[2]))
elif type==3:#deposit cash transaction
instance.setType("DEP")#set type
dateList=msgSp[3]
dateList=dateList.split("/")
instance.setDay(int(dateList[0]))#set dates
instance.setMonth(int(dateList[1]))
instance.setYear(int(dateList[2]))
for i in xrange(len(msgSp)):
if(msgSp[i].find("balance")!=-1):
balIdx=(i+2)
bal=currencyFormat(msgSp[balIdx])
instance.setNewBal(bal)#set new Balance
amt=currencyFormat(msgSp[8])
instance.setAmt(amt)#set deposit amount
elif type==4:#withdraw cash transaction
instance.setType("WIT")#set type
dateList=msgSp[3].split("/")
instance.setDay(int(dateList[0]))#set dates
instance.setMonth(int(dateList[1]))
instance.setYear(int(dateList[2]))
withAmt=currencyFormat(msgSp[8])
instance.setAmt(withAmt)#set amount withdrawn
for i in xrange(len(msgSp)):
if(msgSp[i].find("balance")!=-1):
balIdx=(i+2)
bal=currencyFormat(msgSp[balIdx])
instance.setNewBal(bal)#set new Balance
elif type==5:#purchase Airtime transaction
instance.setType("AIR")#set type
airAmt=currencyFormat(msgSp[4])
instance.setAmt(airAmt)#set airtime amount
if 'for' in msgSp:#purchasing airtime for another user
dateList=msgSp[10].split("/")
else:#purchasing airtime for oneself
dateList=msgSp[8].split("/")
instance.setDay(int(dateList[0]))#set dates
instance.setMonth(int(dateList[1]))
instance.setYear(int(dateList[2]))
for i in xrange(len(msgSp)):
if(msgSp[i].find("balance")!=-1):
balIdx=(i+2)
bal=currencyFormat(msgSp[balIdx])
instance.setNewBal(bal)#set new Balance
elif type==6:#balance inquiry sms
instance.setType("INQ")#set type
balance=currencyFormat(msgSp[6])
instance.setNewBal(balance)#set balance amount
dateList=msgSp[8].split("/")#extract the date
instance.setDay(int(dateList[0]))#set dates
instance.setMonth(int(dateList[1]))
instance.setYear(int(dateList[2]))
instance.setCost(10)#service charge due to inquiry
elif type==7:#bill payment sms
instance.setType("BIL")#set type
balance=currencyFormat(msgSp[len(msgSp)-1])
instance.setNewBal(balance)#set balance amount
for i in xrange(len(msgSp)):
if msgSp[i]=="on":
dateIdx=(i+1)
dateList=msgSp[dateIdx].split("/")#extract the date
instance.setDay(int(dateList[0]))#set dates
instance.setMonth(int(dateList[1]))
instance.setYear(int(dateList[2]))
ent=msgSp.index('to')+1
instance.setEntity(msgSp[ent])#set entity which received payment for the bill
amt=currencyFormat(msgSp[2])
instance.setAmt(amt)
def opening(index, data, months):#method to find a months opening balance.
if index!= 0 and len(data[months[index]-1])!=0:
return data[months[index]-1][len(data[months[index]-1])-1].getNewBal()
else:
first=data[months[index]][0]#first sms for that month
if first.getType()=="DEP" or first.getType()=="REC":#first sms is deposit or receive
opening=first.getNewBal()-first.getAmt()
return opening
elif first.getType()=="AIR":#sms is buying of airtime
opening=first.getNewBal()+first.getAmt()
return opening
elif first.getType()=="WIT" or first.getType()=="SND":
opening=first.getNewBal()+service(first.getAmt())+first.getAmt()
return opening
elif first.getType()=="INQ":
opening=first.getNewBal()+first.getCost()
return opening
def service(amount):#a lookup table for service charges
if amount >= 50 and amount <=100:
return 15
elif amount >= 101 and amount <=2500:
return 25
elif amount >= 2501 and amount <=5000:
return 45
elif amount >= 5001 and amount <=10000:
return 75
elif amount >= 10001 and amount <=20000:
return 145
elif amount >= 20001 and amount <=35000:
return 170
elif amount >= 35001 and amount <=50000:
return 250
elif amount >= 50001 and amount <=70000:
return 300
def currencyFormat(amt):#extracts the currency amount irrespective of the format it is written in and returns an interger
amt=amt.replace("Ksh","").replace(",","").strip()
if '.' in amt:
if amt[-1]=='.':
amt=amt.replace('.',"")
return int(amt)
else:
amt = amt[:amt.index('.')]
return int(amt)
else:
return int(amt)