@@ -0,0 +1,1501 @@
+#! /usr/bin/env python%0Aimport sys%0A%0Afrom csvkit import CSVKitDictWriter%0Afrom lxml import html as etree%0A%0A%0Adef parse_html(path):%0A    html = etree.parse(path)%0A    row_iter = iter(html.xpath('//tr'))%0A%0A    # Throw away the report header in the first row%0A    first_row = next(row_iter)%0A    if len(first_row.getchildren()) == 1:%0A        first_row = next(row_iter)%0A%0A    # The column names are in the second row%0A    header = %5Bcol.text_content() for col in first_row%5D%0A%0A    # Parse dict records from the remaining rows%0A    data = %5B%5D%0A    for row in row_iter:%0A        values = %5Bc.text.strip().strip('%25') if c.text else None for c in row%5D%0A        values = %5Bv if v != 'N/A' else None for v in values%5D%0A        record = dict(zip(header, values))%0A        data.append(record)%0A%0A    return header, data%0A%0A%0Adef html_to_csv(path):%0A    header, data = parse_html(path)%0A%0A    # Create stdout writer%0A    header.insert(2, 'System')%0A    writer = CSVKitDictWriter(sys.stdout, header)%0A    writer.writeheader()%0A%0A    # Parse ID and system before writing each row%0A    for row in data:%0A        id_field = row.pop('FICE')%0A        if not id_field:%0A            continue%0A%0A        # Parse out System that may be in parenthesis in the FICE field%0A        fice_parts = id_field.split(' (')%0A        row%5B'FICE'%5D = fice_parts%5B0%5D%0A        if len(fice_parts) %3E 1:%0A            row%5B'System'%5D = fice_parts%5B1%5D.strip(') ')%0A        else:%0A            row%5B'System'%5D = None%0A%0A        writer.writerow(row)%0A%0A%0Aif __name__ == '__main__':%0A    html_to_csv(sys.argv%5B1%5D)%0A

Add html_to_csv script to convert accountability reports to CSV