Election results in the London Borough of Sutton.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

70 рядки
1.5 KiB

  1. require 'rubygems'
  2. require 'csv'
  3. require 'dm-core'
  4. require 'dm-validations'
  5. require 'dm-timestamps'
  6. require 'lib/models'
  7. # Define parties
  8. # parties = [
  9. # "British National Party",
  10. # "Christian Peoples Alliance",
  11. # "Conservative Party",
  12. # "Green Party",
  13. # "Labour Party",
  14. # "Labour and Co-Operative Party",
  15. # "Liberal Democrats",
  16. # "United Kingdom Independence Party",
  17. # "Libertarian Party"
  18. # ]
  19. #
  20. # for party in parties
  21. # puts party
  22. # Party.create( :name => party )
  23. # end
  24. # Import council candidates
  25. # CSV::Reader.parse(File.open('../candidates-pretty.csv', 'rb')) do |row|
  26. # p row
  27. #
  28. # c = Councilcandidate.new(
  29. # 'forenames' => row[1],
  30. # 'surname' => row[2],
  31. # 'address' => row[4],
  32. # 'postcode' => row[5]
  33. # )
  34. #
  35. # c.ward = Ward.first( :name => row[0] )
  36. # c.party = Party.first( :name => row[3] )
  37. #
  38. # unless c.save
  39. # puts "ERROR: Failed to save candidate"
  40. # c.errors.each do |e|
  41. # puts e
  42. # end
  43. # end
  44. # end
  45. # Import parliament candidates
  46. CSV::Reader.parse(File.open('../parliament-candidates.csv', 'rb')) do |row|
  47. p row
  48. c = Parliamentcandidate.new(
  49. 'forenames' => row[1],
  50. 'surname' => row[2]
  51. )
  52. c.constituency = Constituency.first( :name => row[3] )
  53. c.party = Party.first( :name => row[0] )
  54. unless c.save
  55. puts "ERROR: Failed to save candidate"
  56. c.errors.each do |e|
  57. puts e
  58. end
  59. end
  60. end