Election results in the London Borough of Sutton.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

80 lignes
1.6 KiB

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