def set_fec_id(this_fec_id):
    try:
        
        ftpcandidate = Candidate.objects.filter(cand_id = this_fec_id).order_by('-cycle')[0]
    except __HOLE__:
        print "No candidate found in master file for id=%s" % (this_fec_id)
        return
    print "Got cycle: %s" % (ftpcandidate.cycle)
    this_incumbent, created = Incumbent.objects.get_or_create(fec_id=this_fec_id)
    this_incumbent.cycle='2016'
    this_incumbent.name = ftpcandidate.cand_name
    this_incumbent.fec_id = this_fec_id
    this_incumbent.state = ftpcandidate.cand_office_st
    this_incumbent.office_district = ftpcandidate.cand_office_district
    this_incumbent.office = ftpcandidate.cand_office
    this_incumbent.is_incumbent=True
    this_incumbent.save()
    
    # Now set the incumbent flag in candidate_overlay
    try:
        this_co = Candidate_Overlay.objects.get(fec_id=this_fec_id, cycle='2016')
        this_co.is_incumbent = True
        this_co.save()
        #print "set incumbent %s, %s" % (ftpcandidate.cand_name, this_fec_id)
    except Candidate_Overlay.DoesNotExist:
        pass
        print "Missing candidate: %s, %s" % (ftpcandidate.cand_name, this_fec_id)
dataset/ETHPy150Open sunlightlabs/read_FEC/fecreader/summary_data/management/commands/set_incumbent.py/set_fec_id