"seat_held" : i["seat_held"], "seat_status" : i["seat_status"], "seat_result" : i["seat_result"], } } } }, "Individual" : { "contributor_occupation" : i["contributor_occupation"], "contributor_employer" : i["contributor_employer"], "contributor_gender" : i["contributor_gender"], "contributor_address" : i["contributor_address"], "contributor_city" : i["contributor_city"], "contributor_state" : i["contributor_state"], "contributor_zipcode" : i["contributor_zipcode"], "contributor_category" : i["contributor_category"] } } }}}) jsonData = json.dumps(jsonList) print jsonData # f = open(outFile) # f.write(jsonData) return jsonData data = api.contributions(cycle='2012', contributor_ft="Corrections Corp of America") jsonData = writeJSON(data)
""" 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: # remove frames which are not of interest. del df['candidacy_status'] del df['committee_ext_id'] del df['committee_party'] del df['contributor_ext_id'] del df['cycle'] del df['date'] del df['district_held'] del df['filing_id'] del df['is_amendment']
####################################### import json f = open('congress_full.json', 'r') x = json.load(f) f.close() funding_reps = {} funding_senate = {} cnt = 0 for i in x['objects']: name = i['person']['firstname'] + ' ' + i['person']['lastname'] if i['role_type'] == 'senator': # do shit try: funding_senate[name] = td.contributions(cycle='2012', recipient_ft = name) cnt += 1 except: print "couldn't find senator ", name elif i['role_type'] == 'representative': # do shit try: funding_reps[name] = td.contributions(cycle='2012', recipient_ft = name) cnt += 1 except: print "couldn't find rep ", name else: continue print cnt with open('senate_data.json', 'wb') as fp:
# main argument def main(argv): i = '' outFile = '' try: opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["input=", "output="]) except getopt.error, msg: print "corpSearch.py -i <input> -o <output>" sys.exit(2) for opt, arg in opts: if opt in ("-i", "-input"): i = arg elif opt in ("-o", "-output"): outFile = arg data = [] # if user has typed in a month range, such as between 06 and 11 if i.find("between"): a = i.split() # returns [company name, between, ##, and, ##] name = a[0] dates = "><|2012-" + a[2] + "-01|2012-" + a[4] + "-31" data = api.contributions(cycle='2012', contributor_ft=name, date=dates) else: data = api.contributions(cycle='2012', contributor_ft=i) sectData = readIn("CRP_Categories.txt") sectDict = sectorDict(sectData) jsonData = writeJSON(data, outFile) if __name__ == "__main__": main(sys.argv[1:])
} } } }, "Individual": { "contributor_occupation": i["contributor_occupation"], "contributor_employer": i["contributor_employer"], "contributor_gender": i["contributor_gender"], "contributor_address": i["contributor_address"], "contributor_city": i["contributor_city"], "contributor_state": i["contributor_state"], "contributor_zipcode": i["contributor_zipcode"], "contributor_category": i["contributor_category"] } } } } }) jsonData = json.dumps(jsonList) print jsonData # f = open(outFile) # f.write(jsonData) return jsonData data = api.contributions(cycle='2012', contributor_ft="Corrections Corp of America") jsonData = writeJSON(data)
f = open(outFile, 'w') jsonData = json.dumps(jsonList) print >> f, jsonData # f = open(outFile) # f.write(jsonData) return jsonData # main argument def main(argv): i = '' outFile = '' try: opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["input=", "output="]) except getopt.error, msg: print "corpSearch.py -i <input> -o <output>" sys.exit(2) for opt, arg in opts: if opt in ("-i", "-input"): i = arg elif opt in ("-o", "-output"): outFile = arg data = api.contributions(cycle='2012', contributor_ft=i) sectData = readIn("CRP_Categories.txt") sectDict = sectorDict(sectData) jsonData = writeJSON(data, outFile) if __name__ == "__main__": main(sys.argv[1:])