Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 59 lines (45 sloc) 1.607 kb
#!/usr/bin/env python
from billy.utils import db
from billy.conf import settings
from influenceexplorer import InfluenceExplorer
from urllib2 import HTTPError
import os.path
import sys
api_key = settings.API_KEY
ie = InfluenceExplorer(api_key)
if len(sys.argv) < 2:
print "Need a state to run against (abbr)"
sys.exit(1)
spec = { "state": sys.argv[1] }
if sys.argv[1] == "all":
spec = {}
people = db.legislators.find(spec)
tid_len = 32
for person in people:
full_name = person['full_name'].encode("utf-8")
leg_id = person['leg_id']
if 'transparencydata_id' in person and \
not person['transparencydata_id'] is None and \
person['transparencydata_id'].strip() != "":
tid = person['transparencydata_id']
print tid, leg_id, full_name
total = 0
try:
total = ie.entities.metadata(tid)
years = total['totals'].keys()
years.remove("-1")
years = [int(x) for x in years]
years.sort()
start_year = years[0]
total = total['totals']['-1']['recipient_amount']
total = int(total)
person['_total_contributions'] = total
person['_contributions_start_year'] = start_year
ret = db.legislators.update({"_id": person['_id']},
person,
False, # Upsert
safe=True)
except HTTPError:
print "^" * 32, "%s XXX: <------ Invalid t-ID" % (leg_id)
else:
print " " * 32, leg_id, full_name
Jump to Line
Something went wrong with that request. Please try again.