#!/usr/bin/env python

from __future__ import print_function
from sunlight import capitolwords
from sunlight import congress

for person in capitolwords.phrases_by_entity(
    "legislator",
    phrase="free market",
    sort="count",
):
    n = congress.legislators( bioguide_id=person['legislator'],
        all_legislators="true" )
    if len(n) >= 1:
        n = n[0]
        print( "%s %s %s (%s)" % (
            n['title'], n['firstname'], n['lastname'], n['party']
        ))
    else:
        print( "Missing data on %s" % person['legislator'] )
