-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse170.py
More file actions
91 lines (82 loc) · 3.15 KB
/
parse170.py
File metadata and controls
91 lines (82 loc) · 3.15 KB
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
import csv
import datetime
import dateutil
import json
from dateutil import parser
transactions = []
def parsePrice(input):
toParse = ''
for word in input:
if word.isdigit():
toParse = toParse + word
if toParse == '':
toParse = '0'
return int(toParse)
def processDate(input):
toProcess = ''
wasComma = False
for word in input:
if not wasComma:
toProcess = toProcess + word
if word == ',':
wasComma = True
else:
if word == ' ':
wasComma = False
toProcess = toProcess + word
else:
wasComma = False
toProcess = toProcess + ' ' + word
def processBoolean(input):
if input == 'Y':
return True
elif input == 'F':
return False
with open('170-title-data.csv', mode='r', encoding = "ISO-8859-1") as csvfile:
csv_reader = csv.DictReader(csvfile)
for row in csv_reader:
transactionToAdd = {}
rowDict = dict(row)
transactionToAdd['seller'] = rowDict['Seller']
transactionToAdd['buyer'] = rowDict['Buyer']
transactionToAdd['date'] = rowDict['Date']
transactionToAdd['tax'] = []
transactionToAdd['mortgage'] = []
transactionToAdd['judgement'] = []
transactionToAdd['transactionType'] = rowDict['Transaction Type']
transactionToAdd['price'] = parsePrice(rowDict['Price '])
transactions.append(transactionToAdd)
with open('170-tax-data.csv', mode='r', encoding = "ISO-8859-1") as csvfile:
csv_reader = csv.DictReader(csvfile)
for row in csv_reader:
rowDict = dict(row)
for transaction in transactions:
if transaction['seller'] == rowDict['Owner']:
taxToAdd = {}
taxToAdd['amount'] = parsePrice(rowDict['Amount'])
taxToAdd['year'] = rowDict['Tax year']
taxToAdd['paid'] = processBoolean(rowDict['Taxes Received'])
transaction['tax'].append(taxToAdd)
with open('170-tax-data.csv', mode='r', encoding = "ISO-8859-1") as csvfile:
csv_reader = csv.DictReader(csvfile)
for row in csv_reader:
rowDict = dict(row)
for transaction in transactions:
if transaction['seller'] == rowDict['Owner']:
taxToAdd = {}
taxToAdd['amount'] = parsePrice(rowDict['Amount'])
taxToAdd['year'] = rowDict['Tax year']
taxToAdd['paid'] = processBoolean(rowDict['Taxes Received'])
transaction['tax'].append(taxToAdd)
with open('170-morgage-data.csv', mode='r', encoding = "ISO-8859-1") as csvfile:
csv_reader = csv.DictReader(csvfile)
for row in csv_reader:
rowDict = dict(row)
for transaction in transactions:
if transaction['seller'] == rowDict['Owner']:
taxToAdd = {}
taxToAdd['amount'] = parsePrice(rowDict['Mortgage Amount'])
taxToAdd['balance'] = parsePrice(rowDict['Current Balance'])
transaction['mortgage'].append(taxToAdd)
with open('result170.json', 'w') as fp:
json.dump(transactions, fp)