def create_candidate_from_crp(self, candidate, data): '''Creates a Candidate object based on data from CRP and the FEC. ''' fec_name = generic_querier("SELECT candidate_name FROM fec_candidate_master WHERE candidate_id = %s", [candidate['FECCandID'], ])['candidate_name'] crp_name = re.sub(r'\s\([A-Z0-9]\)', '', candidate.get('FirstLastP', '')) try: return Candidate.objects.get(crp_name=crp_name) except Candidate.DoesNotExist: pass party = re.search(r'\s\(([A-Z0-9])\)$', candidate.get('FirstLastP', '')) if party: party = party.groups()[0] else: party = '' candidate = Candidate.objects.create( fec_id=candidate['FECCandID'], fec_name=fec_name, crp_id=candidate['CID'], crp_name=crp_name, party=party, office=data['candidate_office'], state=data['candidate_state'], district=data['candidate_district'], slug=slugify(crp_name)[:50] ) return candidate
def create_candidate_from_fec(data): result = generic_querier( "SELECT * FROM fec_candidate_master WHERE candidate_id = %s", [ data['candidate_id'], ]) if not result: candidate = Candidate.objects.create( cycle=2012, fec_id=data['candidate_id'], fec_name='%(candidate_first)s %(candidate_last)s' % data, crp_id='', crp_name='', party='', office=data['candidate_office'], state=data['candidate_state'], district=data.get('candidate_district'), slug=slugify('%(candidate_first)s %(candidate_last)s' % data)) return candidate candidate = Candidate.objects.create( cycle=2012, fec_id=result['candidate_id'], fec_name=result['candidate_name'], crp_id='', crp_name='', party=result['party'][0], office=data['candidate_office'], state=data['candidate_state'], district=data.get('candidate_district'), slug=slugify(result['candidate_name'])[:50]) return candidate
def fec_committee_lookup(self, committee_id): query = "SELECT * FROM fec_committee_master WHERE committee_id = %s" params = [committee_id, ] return generic_querier(query, params).get('committee_name', '').strip()
def lookup_candidate_in_crp_table(self, fec_id): return generic_querier("SELECT * FROM candidates WHERE FECCandID = %s", [fec_id, ])
def fec_committee_lookup(cid): query = "SELECT * FROM fec_committee_master WHERE committee_id = %s" params = [cid, ] return generic_querier(query, params)