def build_candidate(candidate_id, candidate_data): name, committee, registration_date, termination_date, location, office, district, ytd_revenues, ytd_expenses, cash_balance = [ (c.text).strip() for c in candidate_data ] if name == 'Candidate name': return None candidate_name = people_names.split_name(name, 'lfm') candidate = { "cfrs_id": candidate_id, "first_name": candidate_name['first_name'], "middle_name": candidate_name['middle_name'], "last_name": candidate_name['last_name'], "slug_name": candidate_name['slug_name'], "committee_name": committee, "committee_slug_name": utils.slugify_string(committee), "registration_date": registration_date, "termination_date": termination_date, "location": location, "office": office, "district": district, "ytd_revenues": mplscf_helper.convert_money_to_decimal(ytd_revenues), "ytd_expenses": mplscf_helper.convert_money_to_decimal(ytd_expenses), "cash_balance": mplscf_helper.convert_money_to_decimal(cash_balance), "created_at": "now()", "updated_at": "now()" } return candidate
def build_record(data, party): committee, address, telephone, registration_id, registration_date, term_date, reports = [(c.text).strip() for c in data] result = { "name": committee, "slug_name": utils.slugify_string(committee), "registration_id": registration_id, "party": party, "created_at": "now()", "updated_at": "now()" } return result
def test_slugify_string(self): self.assertEqual(utils.slugify_string(' harry j potter '), 'harry-j-potter') self.assertEqual(utils.slugify_string('hank green'), 'hank-green') self.assertEqual(utils.slugify_string('AT&T Inc.'), 'att-inc') self.assertEqual(utils.slugify_string('A10 Networks, Inc.'), 'a10-networks-inc') self.assertEqual(utils.slugify_string('58.com Inc..'), '58-com-inc') self.assertEqual(utils.slugify_string('Yum! Brands, Inc.'), 'yum-brands-inc')
def build_contribution(rows, candidate_rid): date, type, contrib_name, city, state, employer, in_kind, in_kind_description, amount, empty = [ (col).strip() for col in rows ] contribution = { "name": contrib_name, "slug_name": utils.slugify_string(contrib_name), "date": date, "city": city, "state": state, "employer": employer, "source_type": type, "target_id": candidate_rid, "in_kind": in_kind, "in_kind_description": in_kind_description, "amount": float(amount.replace(',', '')), "created_at": "now()", "updated_at": "now()", "last_pulled_at": "now()" } get_name_parts(type, contrib_name, contribution) determine_is_lobbyist(type, contribution) return contribution
def build_political_group(data): return { "name": data['text'], "slug_name": utils.slugify_string(data['text']), "registration_id": data['id'] }
def build_candidate(data): return { "committee_name": data['text'], "committee_slug_name": utils.slugify_string(data['text']), "registration_id": data['id'] }