示例#1
0
 def test_parse(self):
     file_path = 'test-data/1229017.fec'
     a_filter = {'filter_itemizations': ['SA']}
     items = fecfile.iter_file(file_path, options=a_filter)
     num_itemizations = 0
     for item in items:
         if item.data_type == 'summary':
             self.assertEqual(item.data['report_code'], '12P')
         if item.data_type == 'itemization':
             num_itemizations += 1
     self.assertEqual(num_itemizations, 186)
示例#2
0
import fecfile
import sys
import ujson as json

for item in fecfile.iter_file('test.fec'):
    sys.stdout.write(json.dumps(item.data) + '\n')
示例#3
0
def file_location_xlsx(file_path, filename):
    items = fecfile.iter_file(file_path)
    fec2xlsx.make_xlsx(items, filename)
示例#4
0
def test_save_filing(tmpdir):
    db_path = str(tmpdir / "data.db")
    db = sqlite_utils.Database(db_path)
    fec_path = str(pathlib.Path(__file__).parent / "1146148.fec")
    save_filing(fecfile.iter_file(fec_path), db)
    assert {"itemizations", "filings"} == set(db.table_names())
    assert [{
        "id": "934ddbec213c17d6290959b607f3480a3b5039c7",
        "header_record_type": "HDR",
        "header_ef_type": "FEC",
        "header_fec_version": "8.1",
        "header_soft_name": "NGP Campaign Office (R)",
        "header_soft_ver": "6",
        "header_report_id": "",
        "header_report_number": "",
        "header_comment": "\n",
        "form_type": "F5N",
        "filer_committee_id_number": "C90004185",
        "entity_type": "ORG",
        "organization_name": "NARAL Pro-Choice America",
        "individual_last_name": "",
        "individual_first_name": "",
        "individual_middle_name": "",
        "individual_prefix": "",
        "individual_suffix": "",
        "change_of_address": "",
        "street_1": "1150 15th Street, NW",
        "street_2": "",
        "city": "Washington",
        "state": "DC",
        "zip_code": "20005",
        "individual_occupation": "",
        "individual_employer": "",
        "report_code": "YE",
        "report_type": "",
        "original_amendment_date": "",
        "coverage_from_date": "2016-10-01 00:00:00-04:00",
        "coverage_through_date": "2016-12-31 00:00:00-05:00",
        "total_contribution": 0.0,
        "total_independent_expenditure": 221670.4,
        "person_completing_last_name": "Robinson",
        "person_completing_first_name": "Kimbery",
        "person_completing_middle_name": "",
        "person_completing_prefix": "",
        "person_completing_suffix": "",
        "date_signed": "2017-01-31 00:00:00-05:00",
    }] == list(db["filings"].rows)
    assert [
        {
            "id": "6659e05d3514e6e325140d610eff0c91bb11d4b5",
            "form_type": "F57",
            "filer_committee_id_number": "C90004185",
            "transaction_id_number": "VN7C2A4VPA0",
            "entity_type": "ORG",
            "payee_organization_name": "Chong & Koster",
            "payee_last_name": "",
            "payee_first_name": "",
            "payee_middle_name": "",
            "payee_prefix": "",
            "payee_suffix": "",
            "payee_street_1": "1640 Rhode Island Ave NW",
            "payee_street_2": "Ste 600",
            "payee_city": "Washington",
            "payee_state": "DC",
            "payee_zip_code": "200363229",
            "election_code": "G2016",
            "election_other_description": "",
            "dissemination_date": "2016-10-05 00:00:00-04:00",
            "expenditure_amount": 17721.5,
            "calendar_y_t_d_per_election_office": 23837.5,
            "expenditure_purpose_descrip":
            "Media time buy & production expense",
            "category_code": "",
            "payee_cmtte_fec_id_number": "",
            "support_oppose_code": "O",
            "candidate_id_number": "S0NH00235",
            "candidate_last_name": "AYOTTE",
            "candidate_first_name": "KELLY A",
            "candidate_middle_name": "",
            "candidate_prefix": "",
            "candidate_suffix": "",
            "candidate_office": "S",
            "candidate_state": "NH",
            "candidate_district": "00\n",
            "filing_id": "934ddbec213c17d6290959b607f3480a3b5039c7",
        },
        {
            "id": "b8a83bcf4383a1b17b7fbba599d495d5348063a9",
            "form_type": "F57",
            "filer_committee_id_number": "C90004185",
            "transaction_id_number": "VN7C2A4VPB7",
            "entity_type": "ORG",
            "payee_organization_name": "Chong & Koster",
            "payee_last_name": "",
            "payee_first_name": "",
            "payee_middle_name": "",
            "payee_prefix": "",
            "payee_suffix": "",
            "payee_street_1": "1640 Rhode Island Ave NW",
            "payee_street_2": "Ste 600",
            "payee_city": "Washington",
            "payee_state": "DC",
            "payee_zip_code": "200363229",
            "election_code": "G2016",
            "election_other_description": "",
            "dissemination_date": "2016-10-05 00:00:00-04:00",
            "expenditure_amount": 27740.5,
            "calendar_y_t_d_per_election_office": 36281.0,
            "expenditure_purpose_descrip":
            "Media time buy & production expense",
            "category_code": "",
            "payee_cmtte_fec_id_number": "",
            "support_oppose_code": "O",
            "candidate_id_number": "S6NV00218",
            "candidate_last_name": "HECK",
            "candidate_first_name": "JOE",
            "candidate_middle_name": "",
            "candidate_prefix": "",
            "candidate_suffix": "",
            "candidate_office": "S",
            "candidate_state": "NV",
            "candidate_district": "00\n",
            "filing_id": "934ddbec213c17d6290959b607f3480a3b5039c7",
        },
        {
            "id": "0626839762b80945a76eae8a663189cba26f452d",
            "form_type": "F57",
            "filer_committee_id_number": "C90004185",
            "transaction_id_number": "VN7C2A4VPC5",
            "entity_type": "ORG",
            "payee_organization_name": "Chong & Koster",
            "payee_last_name": "",
            "payee_first_name": "",
            "payee_middle_name": "",
            "payee_prefix": "",
            "payee_suffix": "",
            "payee_street_1": "1640 Rhode Island Ave NW",
            "payee_street_2": "Ste 600",
            "payee_city": "Washington",
            "payee_state": "DC",
            "payee_zip_code": "200363229",
            "election_code": "G2016",
            "election_other_description": "",
            "dissemination_date": "2016-10-05 00:00:00-04:00",
            "expenditure_amount": 65145.7,
            "calendar_y_t_d_per_election_office": 80796.7,
            "expenditure_purpose_descrip":
            "Media time buy & production expense",
            "category_code": "",
            "payee_cmtte_fec_id_number": "",
            "support_oppose_code": "O",
            "candidate_id_number": "S4PA00121",
            "candidate_last_name": "TOOMEY",
            "candidate_first_name": "PATRICK JOSEPH",
            "candidate_middle_name": "",
            "candidate_prefix": "",
            "candidate_suffix": "",
            "candidate_office": "S",
            "candidate_state": "PA",
            "candidate_district": "00\n",
            "filing_id": "934ddbec213c17d6290959b607f3480a3b5039c7",
        },
        {
            "id": "ccc70aa47480385031db0b252a7cf8bc2fd380d8",
            "form_type": "F57",
            "filer_committee_id_number": "C90004185",
            "transaction_id_number": "VN7C2A4VPD3",
            "entity_type": "ORG",
            "payee_organization_name": "Chong & Koster",
            "payee_last_name": "",
            "payee_first_name": "",
            "payee_middle_name": "",
            "payee_prefix": "",
            "payee_suffix": "",
            "payee_street_1": "1640 Rhode Island Ave NW",
            "payee_street_2": "Ste 600",
            "payee_city": "Washington",
            "payee_state": "DC",
            "payee_zip_code": "200363229",
            "election_code": "G2016",
            "election_other_description": "",
            "dissemination_date": "2016-10-05 00:00:00-04:00",
            "expenditure_amount": 110607.7,
            "calendar_y_t_d_per_election_office": 140460.2,
            "expenditure_purpose_descrip":
            "Media time buy & production expense",
            "category_code": "",
            "payee_cmtte_fec_id_number": "",
            "support_oppose_code": "O",
            "candidate_id_number": "P80001571",
            "candidate_last_name": "TRUMP",
            "candidate_first_name": "DONALD",
            "candidate_middle_name": "J",
            "candidate_prefix": "",
            "candidate_suffix": "",
            "candidate_office": "P",
            "candidate_state": "00",
            "candidate_district": "00\n",
            "filing_id": "934ddbec213c17d6290959b607f3480a3b5039c7",
        },
        {
            "id": "18784acd68bef3ab5c3ace49c3085d1d22538b01",
            "form_type": "F57",
            "filer_committee_id_number": "C90004185",
            "transaction_id_number": "VN7C2A4Y2X9",
            "entity_type": "ORG",
            "payee_organization_name": "Chong & Koster",
            "payee_last_name": "",
            "payee_first_name": "",
            "payee_middle_name": "",
            "payee_prefix": "",
            "payee_suffix": "",
            "payee_street_1": "1640 Rhode Island Ave NW",
            "payee_street_2": "Ste 600",
            "payee_city": "Washington",
            "payee_state": "DC",
            "payee_zip_code": "200363229",
            "election_code": "G2016",
            "election_other_description": "",
            "dissemination_date": "2016-10-06 00:00:00-04:00",
            "expenditure_amount": 455.0,
            "calendar_y_t_d_per_election_office": 23837.5,
            "expenditure_purpose_descrip": "Media time buy",
            "category_code": "",
            "payee_cmtte_fec_id_number": "",
            "support_oppose_code": "O",
            "candidate_id_number": "S0NH00235",
            "candidate_last_name": "AYOTTE",
            "candidate_first_name": "KELLY A",
            "candidate_middle_name": "",
            "candidate_prefix": "",
            "candidate_suffix": "",
            "candidate_office": "S",
            "candidate_state": "NH",
            "candidate_district": "00\n",
            "filing_id": "934ddbec213c17d6290959b607f3480a3b5039c7",
        },
    ] == list(db["itemizations"].rows)