-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_extractor.py
69 lines (64 loc) · 2.48 KB
/
data_extractor.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
from pickle import load
from datetime import datetime
from time import mktime
def StateBankIndia(raw_data):
def convert_date(raw_date):
return int(mktime(datetime.strptime(raw_date, "%d %b %Y").timetuple()))
formated_data = [row.split("\t") for row in raw_data.split("\n")]
final_data = []
row_num = 20
while True:
if(len(formated_data[row_num]) >= 5):
transaction_date = convert_date(formated_data[row_num][0])
details = formated_data[row_num][2].strip()
if(formated_data[row_num][4] != " "):
debit_amount = float(formated_data[row_num][4].replace(",", ""))
else:
debit_amount = ""
if(formated_data[row_num][5] != " "):
credit_amount = float(formated_data[row_num][5].replace(",", ""))
else:
credit_amount = ""
if(formated_data[row_num][6] != " "):
balance_amount = float(formated_data[row_num][6].replace(",", ""))
else:
balance_amount = ""
final_data.append(
(transaction_date, details, debit_amount, credit_amount, balance_amount))
else:
break
row_num = row_num+1
return final_data
def ICICI(raw_data):
def convert_date(raw_date):
return int(mktime(datetime.strptime(raw_date, "%d/%m/%Y").timetuple()))
formated_data = [row.split(",") for row in raw_data.split("\n")]
final_data = []
row_num = 1
while True:
if(len(formated_data[row_num]) >= 5):
transaction_date = convert_date(formated_data[row_num][0])
details = formated_data[row_num][1].strip()
if(formated_data[row_num][2] != "0"):
debit_amount = float(formated_data[row_num][2])
else:
debit_amount = ""
if(formated_data[row_num][3] != "0"):
credit_amount = float(formated_data[row_num][3])
else:
credit_amount = ""
if(formated_data[row_num][5] != " "):
balance_amount = float(formated_data[row_num][5])
else:
balance_amount = ""
final_data.append(
(transaction_date, details, debit_amount, credit_amount, balance_amount))
else:
break
row_num = row_num+1
return final_data
def factory(bank_name):
if(bank_name=='sbh'):
return StateBankIndia
elif(bank_name=='icici'):
return ICICI