#!/usr/bin/python -tt # Stephen Muchovej apikey = 'your_api_key' import sys from sunlight import openstates from transparencydata import TransparencyData td = TransparencyData(apikey) import pandas as pd """ This program obtains general information on the donors to a particular legislator. It first obtains all the legislators for the state of CA, and then cycles through all of those to keep relevant information and put it in a pandas data frame. It then writes that pandas dataframe to a mysql database """ # obtain the list of legislators in teh current session all_legs = openstates.legislators(state='ca') # obtain all donor information for the particular legislator in the past 3 years. index = -1 for leg in all_legs: thiscontribution = td.contributions(cycle='2013|2014|2015', recipient_ft=leg['last_name'].lower(), recipient_state='ca') df = pd.DataFrame(thiscontribution) # df.columns has the name of the column index = index + 1 print index if not df.empty:
# August Guang, February 2013 # corpSearch.py # Takes in an input term (corporation name) and scrapes the InfluenceExplorer # to run: python corpSearch.py -i <input> -o <output> from transparencydata import TransparencyData import sys, getopt #import requests import pprint import itertools import json api = TransparencyData('8f0d91c66d4e428da018c0eb0fa571fc') # reads CRP_Categories.txt def readIn(inFile): with open(inFile, 'r') as fin: # format is: # Catcode Catname Catorder Industry Sector Sector_Long tmp = fin.readlines() sectData = tmp[1:] return sectData # sorts CRP_Categories.txt so that all codes are associated with a sector in a dictionary # this allows us to look up a code in the dictionary def sectorDict(sectData): sectDict = {} for i in sectData: sector = i.split()[4] code = i.split()[0]