FECHell
Parsing a loading electronically filed fundraising reports from the Federal Election Commission. FECHell uses format definition files from Watchdog.net (watchdog.net/data/crawl/fec/electronic/headers/).
Install
sudo gem install offensivepolitics-fechell
Usage
require ‘rubygems’ require ‘fechell’ require ‘open-uri’
# convenience function to download a file from a URL and save it locally
def savefile(filename,url) File.open(filename,“w”) do |file| file.puts open(url).read end end
h = FECHell.new
# Grab the year-end fundraising reports by candidates for the 5th district of Virginia. This race was incredibly close and decided by less than 800 votes.
# fetch Goode for Congress F3, Year End 2008 savefile(“goode.fec”,“query.nictusa.com/dcdev/posted/392684.fec”)
# fetch Perriello for Congress F3, Year end 2008 savefile(‘perriello.fec’,“query.nictusa.com/dcdev/posted/401630.fec”)
# extract the financial summary of each campaign. we want total receipts this period and cycle to date, total disbursements this period and cycle to date, # and the cash position at the beginning and end of this reporting period
[‘goode.fec’,‘perriello.fec’].each do |filename| h.process(filename) do |v| schedule = v values = v next if schedule != ‘F3’ puts “For ‘#NAME’]‘”
puts “Total receipts this period: #A 24. Total Receipts this Period’]” puts “Total receipts cycle-to-date: #B 16. Total Receipts’]” puts “Total disbursements this period: #A 26. Total Disbursements this Period’]” puts “Total disbursements cycle-to-date: #B 22. Total Disbursements’]” puts “Cash-on-hand beginning of period: #A 23. Cash Beginning Reporting Period’]” puts “Cash-on-hand end of period: #A 27. Cash on hand at Close Period’]” puts “n” end end
# From this output we see that Rep Goode outspent Perriello by more than a million dollars, but still lost his seat by 727 votes.
puts “===”
# fetch HuckPac F3X, Post General, 2008 savefile(‘huckpac.fec’,‘query.nictusa.com/dcdev/posted/407479.fec’) # extract disbursements (schedule B) made this period by HuckPAC with the expenditure purpose(key=“EXPENDITURE PURPOPOSE DESCRIPTION”) of “Payroll” puts “TO,DATE,AMOUNT” h.process(“huckpac.fec”) do |v| schedule = v values = v
next if schedule != ‘SB’
next if values[‘EXPENDITURE PURPOSE DESCRIP’] != ‘Payroll’
puts “#FIRST NAME’] #LAST NAME’],#DATE’],#AMOUNT’]”
end
# From this we can see that HuckPAC keeps 5 full-time people on staff, including his daughter Sarah.
Changes
0.1.8
Prepended "Column A" or "Column B" to forms F3,F3P,F3X,F3Z for all FEC DEF files to accommodate duplicate key names.
Added HDR records to all the FEC DEF files
Updated schedule identifier to allow HDR (header) lines to pass through system
0.1.7
Added support for the FEC header line (schedule=HDR) to format files 5.0-6.4
0.1.6
Fixed version numbers in FECHell::Versions
0.1.5
Fixed optional 'options' parameter to FECHell::process() call
0.1.4
Added support for FEC file 6.4
0.1.3
Removed extra files from distribution.
0.1.2
Added fastercsv gem as an install dependency
0.1.1
Added support for version 6.3 FEC files
Todo
- Normalize KEY names in DEF files (NO vs No, etc)
- Support v3.0 electronic filing
- Better error checking on failed schedule identification.
- Convert Watchdog.net CSV files into ruby classes