Ejemplo n.º 1
0
#!/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:
Ejemplo n.º 2
0
import csv
import json
from transparencydata import TransparencyData
from influenceexplorer import InfluenceExplorer

td = TransparencyData('4df4c44769f4411a982d024313deb894')

api = InfluenceExplorer('4df4c44769f4411a982d024313deb894')

# Dictionary for ids->[name, probably party]
crp_ids = {}

with open('CRP_IDs.csv', 'rb') as f:
    reader = csv.reader(f)
    for row in reader:
        if(row[0] != ''):
            crp_ids[row[0]] = [row[1],row[2]]


# Dictionary for names-> td_ids
# We can use these td_ids to access the
# influence explorer methods.
#cand_ids = {}
#for cand_id in crp_ids:
#    try:
#   	ent = api.entities.id_lookup(namespace='urn:crp:recipient', id=str(cand_id))
#        cand_ids[crp_ids[cand_id][0]] = ent[0][u'id'].encode('ascii')
#        print 'found candidate ', crp_ids[cand_id][0]
#    except:
#        print 'error in finding candidate ' + crp_ids[cand_id][0] + ' in database'
#        continue
Ejemplo n.º 3
0
# 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]
Ejemplo n.º 4
0
# 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]
Ejemplo n.º 5
0
from influenceexplorer import InfluenceExplorer
from transparencydata import TransparencyData
import numpy as np
import matplotlib.pyplot as plt

api_key = '81ae602f16f34cbc9fe2643c7691f3d3'

ie = InfluenceExplorer(api_key)
td = TransparencyData(api_key)

city_name = ""

while city_name != "0":

    city_name = raw_input("Enter a city: ")
    state_name = raw_input("Enter a state abbreviation: ")
    
    bTotal = []
    oTotal = []
    sTotal = []
    hTotal = []
    
    for i in td.earmarks(city=city_name, state=state_name):
        print i['fiscal_year'], 
        print "Budget:", i['budget_amount'], 
        print "\tOmni:", i['omni_amount'], 
        print "\tSenate", i['senate_amount'], 
        print "\tHouse:", i['house_amount'], 
        print "\n\t", 
        print i['members'], 
        print "\n\t", 
Ejemplo n.º 6
0
# 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]
Ejemplo n.º 7
0
# 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:
Ejemplo n.º 8
0
# August Guang, February 2013
# corpSearch.py
# Takes in an input term (corporation name) and scrapes the InfluenceExplorer

# to run: python corpSearch.py -i <input>

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]