def main(): dna = common.get_dna(INPUT_FILE) results = set() for section in re_section.finditer(dna): section_map = section.groupdict() cu_model = section_map['cu_model'] cu_mop = section_map['cu_mop'] cu_mca = section_map['cu_mca'] section_text = ' '.join(map(str.strip, section.groups())) for type_name, pattern in PATTERNS: for line_match in pattern.finditer(section_text): sys_map = line_match.groupdict() sys_map.pop('junk') sys_map['cu_model'] = cu_model sys_map['cu_mop'] = cu_mop sys_map['cu_mca'] = cu_mca sys_map['brand'] = BRAND sys_map['type'] = type_name sys_map = {k: common.trycast(v) for k, v in sys_map.items()} prices = sum(p for k, p in sys_map.items() if 'price' in k and 'system' not in k and p > 0) sys_map['cu_price'] = sys_map['system_price'] - prices size = round(sys_map['cu_btu'] / 12000 / 0.5) * 0.5 if math.isclose(size, 4.5): size = 5 sys_map['size'] = size results.add(tuple(sorted(sys_map.items()))) results = [dict(t) for t in results] print(f'...writing {len(results)} results to {SAVE_FILE}') with open(SAVE_FILE, 'w', newline='') as f: w = csv.DictWriter(f, fieldnames=common.FIELDS) w.writeheader() w.writerows(results)
def main(): with open(INPUT_FILE) as f: file_txt = f.read().replace(',', '') file_txt = file_txt.split('\n') results = set() cu_map = None working_re = None for line in file_txt: m = re_section_header.match(line) if m: cu_map = m.groupdict() continue if line.startswith('Furnace'): working_re = PATTERNS[2:] continue elif line.startswith('Air Handler'): working_re = PATTERNS[:2] continue if cu_map is None or working_re is None: continue if cu_map['cu_model'].startswith('M'): cu_map = working_re = None continue sys_map = get_re_dict(line, working_re) if sys_map is None: continue sys_map = {**cu_map, **sys_map} sys_map['brand'] = BRAND sys_map = {k: common.trycast(v) for k, v in sys_map.items()} results.add(tuple(sorted(sys_map.items()))) results = [dict(t) for t in results] print(f'...writing {len(results)} results to {SAVE_FILE}') with open(SAVE_FILE, 'w', newline='') as f: w = csv.DictWriter(f, fieldnames=common.FIELDS) w.writeheader() w.writerows(results)
def cns(item): return trycast(item.strip().replace('$', '').replace(',', ''))