def process_file(filename):
    print "Processing file %s" % (filename)
    # read the whole file -- slow, but...
    membership_records = yaml.load(open(filename, 'r'))
    #print membership_records
    for membership in membership_records:
        # We only care about committees, not subcomittees. These have 4-letter thomas_ids. The subcommittees are \w{4}\d{2}
        if len(membership)==4:
            print membership
            committee = Committee.objects.get(thomas_id=membership)
            print "Processing committee %s" % (committee)
            for member in membership_records[membership]:
                bioguide = member['bioguide']
                
                legislator = Legislator.objects.get(bioguide=bioguide)
                print "Adding %s" % (legislator.last_name)
                try:
                    CurrentCommitteeMembership.objects.get(committee=committee, member=legislator)
                except CurrentCommitteeMembership.DoesNotExist:
                    CurrentCommitteeMembership.objects.create(
                        committee=committee,
                        member=legislator,
                        rank = member['rank'],
                        party = member['party'],
                        title = member.get('title'),
                        )
dataset/ETHPy150Open sunlightlabs/read_FEC/fecreader/legislators/management/commands/load_committee_membership.py/process_file/original