|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- require_relative '../models'
- require 'pp'
-
-
-
-
-
-
-
- @election = Election.get(ARGV.shift)
-
- CSV.foreach(ARGV.shift) do |line|
- district_name, candidate_name, party, votes, seats = line
-
- pp line
-
-
- @district = District.first(:name => district_name)
-
- puts @district.name
-
-
-
- bits = candidate_name.split(" ")
- candidate_forenames = bits[0..-2].join(" ")
- candidate_surname = bits.last
-
-
-
-
-
-
- @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,
- :seats => seats
- )
-
- unless @candidacy.saved?
- $stderr.puts "Couldn't save candidacy #{@candidacy}"
- exit 1
- end
-
- end
|