#!/usr/bin/env python3 import glob, datetime, json out_file = 'masterlist.csv' base_fp = 'out/2020_singles' files = glob.glob('{}/*.json'.format(base_fp)) with open(out_file, 'w') as write_f: 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') for fp in files: contents = None with open(fp, 'r') as read_f: contents = json.loads(read_f.read()) read_f.close() if contents == None: raise Exception('Contents cannot be none for {}'.format(fp)) owner_info = contents.pop('owner_info') row = list(map(lambda x: str(x), contents.values())) row.append(owner_info['owner_1']) if owner_info['owner_2']: row.append(owner_info['owner_2']) else: row.append('') row.append(owner_info['address_1']) row.append(owner_info['city']) row.append(owner_info['state']) row.append(owner_info['zip']) row = '|'.join(row) write_f.write('{}\n'.format(row)) write_f.close()