|
- require_relative '../models'
- require 'pp'
-
-
-
-
-
-
-
- @election = Election.get(ARGV.shift)
-
- ARGF.each do |line|
- district_name, candidate_name, party, votes, elected = line.split("\t").map{ |e| e.strip }
-
-
- @district = District.first(:name => district_name)
-
-
-
-
-
-
-
-
- bits = candidate_name.split(", ")
- candidate_forenames = bits[1]
- candidate_surname = bits[0]
-
- @candidate = Candidate.first_or_create(:forenames => candidate_forenames, :surname => candidate_surname)
-
- pp @candidate
- unless @candidate.saved?
- $stderr.puts "Couldn't save candidate #{@candidate}"
- exit 1
- end
-
-
-
- @party = Party.first_or_create(:name => party)
-
- puts @party.name
- unless @party.saved?
- $stderr.puts "Couldn't save party #{@party}"
- exit 1
- end
-
-
- @candidacy = Candidacy.create(
- :election => @election,
- :candidate => @candidate,
- :party => @party,
- :district => @district,
- :votes => votes
- )
-
- unless @candidacy.saved?
- $stderr.puts "Couldn't save candidacy #{@candidacy}"
- exit 1
- end
-
- end
|