adds license
[west_allis_property_tax] / json_to_csv
1 #!/usr/bin/env python3
2
3 import glob, datetime, json
4
5 out_file = 'masterlist.csv'
6 base_fp = 'out/2020_singles'
7 files = glob.glob('{}/*.json'.format(base_fp))
8
9 with open(out_file, 'w') as write_f:
10     write_f.write('prop_type|parcel_num|municipality|property_address|bill_num|net_mill_rate|lottery_claims_num|lottery_claims_date|lottery_claims_amount|gross_tax|school_credit|total_tax|first_dollar_credit|lottery_credit_amount|net_tax|net_tax_paid|net_tax_due|special_assessments|special_assessments_paid|special_assessments_due|special_charges|special_charges_paid|special_charges_due|delinquent_utility|delinquent_utility_paid|delinquent_utility_due|private_forest_crop|private_forest_crop_paid|private_forest_crop_due|woodland_tax_law|woodland_tax_law_paid|woodland_tax_law_due|managed_forest_land|managed_forest_land_paid|managed_forest_land_due|other_charges|other_charges_paid|other_charges_due|interest_paid|interest_due|penalty_paid|penalty_due|total_taxes|total_paid|total_due|installments|payments|tax_history|details|created_on|owner_1|owner_2|address_1|city|state|zip\n')
11
12     for fp in files:
13         contents = None
14         with open(fp, 'r') as read_f:
15             contents = json.loads(read_f.read())
16             read_f.close()
17
18         if contents == None:
19             raise Exception('Contents cannot be none for {}'.format(fp))
20
21
22         owner_info = contents.pop('owner_info')
23
24         row = list(map(lambda x: str(x), contents.values()))
25         row.append(owner_info['owner_1'])
26
27         if owner_info['owner_2']:
28             row.append(owner_info['owner_2'])
29         else:
30             row.append('')
31
32         row.append(owner_info['address_1'])
33         row.append(owner_info['city'])
34         row.append(owner_info['state'])
35         row.append(owner_info['zip'])
36
37         row = '|'.join(row)
38         write_f.write('{}\n'.format(row))
39
40     write_f.close()
41