def import_committees_from_legislators(current_term, abbr):
<EOL>for legislator in db.legislators.find({'<STR_LIT>': {'<STR_LIT>': {<EOL>'<STR_LIT>': current_term, settings.LEVEL_FIELD: abbr}}}):<EOL><INDENT>for role in legislator['<STR_LIT>']:<EOL><INDENT>if (role['<STR_LIT:type>'] == '<STR_LIT>' and<EOL>'<STR_LIT>' not in role):<EOL><INDENT>spec = {settings.LEVEL_FIELD: abbr,<EOL>'<STR_LIT>': role['<STR_LIT>'],<EOL>'<STR_LIT>': role['<STR_LIT>']}<EOL>if '<STR_LIT>' in role:<EOL><INDENT>spec['<STR_LIT>'] = role['<STR_LIT>']<EOL><DEDENT>committee = db.committees.find_one(spec)<EOL>if not committee:<EOL><INDENT>committee = spec<EOL>committee['<STR_LIT>'] = '<STR_LIT>'<EOL>committee[settings.LEVEL_FIELD] =legislator[settings.LEVEL_FIELD]<EOL>committee['<STR_LIT>'] = []<EOL>committee['<STR_LIT>'] = []<EOL>if '<STR_LIT>' not in committee:<EOL><INDENT>committee['<STR_LIT>'] = None<EOL><DEDENT>insert_with_id(committee)<EOL><DEDENT>for member in committee['<STR_LIT>']:<EOL><INDENT>if member['<STR_LIT>'] == legislator['<STR_LIT>']:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>committee['<STR_LIT>'].append(<EOL>{'<STR_LIT:name>': legislator['<STR_LIT>'],<EOL>'<STR_LIT>': legislator['<STR_LIT>'],<EOL>'<STR_LIT>': role.get('<STR_LIT>') or '<STR_LIT>'})<EOL>for source in legislator['<STR_LIT>']:<EOL><INDENT>if source not in committee['<STR_LIT>']:<EOL><INDENT>committee['<STR_LIT>'].append(source)<EOL><DEDENT><DEDENT>db.committees.save(committee, safe=True)<EOL>role['<STR_LIT>'] = committee['<STR_LIT>']<EOL><DEDENT><DEDENT><DEDENT>db.legislators.save(legislator, safe=True)<EOL><DEDENT>
create committees from legislators that have committee roles