Created
January 31, 2009 02:30
-
-
Save knowtheory/55412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'merb' | |
require 'config/dependencies' | |
app_models = Pathname.new("app/models") | |
Dir.open(app_models).each do |model| | |
path = app_models / model | |
# puts "Requring " + path if path.to_s =~ /\.rb$/ | |
require path if path.to_s =~ /\.rb$/ | |
end | |
require "lib/access_congress/dm_types" | |
import_lib = Pathname.new("lib/access_congress/importer") | |
Dir.open(import_lib).each do |model| | |
path = import_lib / model | |
# puts "Requring " + path if path.to_s =~ /\.rb$/ | |
require path if path.to_s =~ /\.rb$/ | |
end | |
class GovHub < Thor | |
desc "import path_to_session [all | members | bills | roll_calls]", "Imports data for target class (and associated support classes)" | |
def import(session_path, import_type="all") | |
case import_type | |
when "members" | |
import_members(session_path) | |
when "bills" | |
import_bills(session_path) | |
when "roll_calls" | |
import_roll_calls(session_path) | |
when "all" | |
import_members(session_path) | |
import_bills(session_path) | |
import_roll_calls(session_path) | |
else | |
raise ArgumentError, "you have not specified a valid type to import ('#{import_type}'?)." | |
end | |
end | |
desc "import_all path_to_corpus_root [all | members | bills | roll_calls]", "Import all the data we can ferret out from document root" | |
def import_all(corpus_path, import_type="all") | |
path = Pathname.new(corpus_path) | |
if File.exists?(path) | |
corpus_dir = Dir.open(path) | |
corpus_dir.map do |filename| | |
if filename =~ /\d+/ and (path / filename).directory? | |
import(corpus_path / filename, import_type) | |
else | |
puts "" | |
end | |
end | |
end | |
end | |
private | |
def import_members(session_path) | |
path = session_path / "repstats/people.xml" | |
if File.exists?(path) | |
puts "[IMPORT]\tMembers, Member Roles, and Committee Positions" | |
::Members.import(path) | |
else | |
puts "[SKIP]\t\tMembers:\t#{path} doesn't exist." | |
end | |
end | |
def import_bills(session_path) | |
path = session_path / "bills" | |
if File.exists?(path) | |
puts "[IMPORT]\tBills, Cosponsors, Titles, Records, Related Bills, Committees, Subjects" | |
bill_dir = Dir.open(path) | |
bill_dir.map do |bill_name| | |
if bill_name =~ /\.xml$/ | |
bill_path = path / bill_name | |
::Bill.import(bill_path) | |
end | |
end | |
else | |
puts "[SKIP]\t\tBills:\t\t#{path} doesn't exist." | |
end | |
end | |
def import_roll_calls(session_path) | |
path = session_path / "rolls" | |
if File.exists?(path) | |
puts "[IMPORT]\tRoll Calls, Votes for Roll Calls" | |
roll_call_dir = Dir.open(path) | |
roll_call_dir.map do |roll_call_name| | |
if roll_call_name =~ /\.xml$/ | |
roll_call_path = path / roll_call_name | |
::RollCall.import(roll_call_path) | |
end | |
end | |
else | |
puts "[SKIP]\t\tRoll Calls:\t#{path} doesn't exist." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment