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

# remove old versions from github installs

sudo gem uninstall offensivepolitics-fechell

# install new version hosted @ gemcutter / rubygems.org sudo gem install fechell

Usage

require ‘rubygems’ require ‘fechell’ require ‘fechell/forms.rb’ 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

# note we’re using the new FECForm.form_for function that takes any version FECHell parameter hash and returns a full ruby object [‘goode.fec’,‘perriello.fec’].each do |filename| fec_version, original_form_type, form_type, values = h.header_lines(filename) next unless form_type == “F3” && fec_version.to_i >= 3 f = FECForm.schedule_for(form_type, fec_version, values) puts “For: #ff.committee_name” puts “Total receipts this period: #ff.col_A_line_24” puts “Total receipts cycle-to-date: #ff.col_B_line_16” puts “Total disbursements this period: #ff.col_A_line_26” puts “Total disbursements cycle-to-date: #ff.col_B_line_22” puts “Cash-on-hand beginning of period: #ff.col_A_line_23” puts “Cash-on-hand end of period: #ff.col_A_line_27” puts “nn” 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” # still using the previous hash syntax since the object model for F3X forms isn’t done yet 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.2.0
  Updated CSV definition for V7.0 of FECFile.
  Added tests for V7.0, except Schedule C/1 since nobody has filed an actual for yet!
0.1.9
  Massive speedup in form-type detection
  Dozens of changes to definition files 
  Several bug-fixes for early format 5.0 files
  Initial support for V3.0 files (circa early 2000)
  Added FEC version-independent Form classes that can transform a FECHell hash into an actual class
  Added monolithic unit test for every file version for the following schedules / forms: F3, SA, SB, SC, SC1
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

Add unit tests for Schedule C v2 (SC2)
Add Form class definition for missing form types (F1,F2,F3X,F3P)