Skip to content

Instantly share code, notes, and snippets.

@twneale
Last active December 16, 2016 19:15
Show Gist options
  • Save twneale/7f174ec2adb46340c03f to your computer and use it in GitHub Desktop.
Save twneale/7f174ec2adb46340c03f to your computer and use it in GitHub Desktop.
Calculating legislator ideal points with Python
from sunlight import openstates, response_cache
from pscl.ext.openstates import RollcallBuilder
response_cache.enable('mongo')
response_cache.logger.setLevel(10)
spec = dict(state='al', chamber='lower', search_window='term:2011-2014')
valid_ids = [leg['id'] for leg in openstates.legislators(spec)]
builder = RollcallBuilder(valid_ids)
bills = openstates.bills(spec)
for bill in bills:
bill = openstates.bill(bill['id'])
for vote in bill['votes']:
if vote['chamber'] != bill['chamber']:
continue
builder.add_vote(vote)
rollcall = builder.get_rollcall()
wnominate = rollcall.wnominate(polarity=('ALL000086', 'ALL000085'))
wnom_values = wnominate.legislators.coord1D
ideal = rollcall.ideal()
ideal_values = ideal.xbar
import pdb; pdb.set_trace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment