Election results in the London Borough of Sutton.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
1.1 KiB

  1. # require_relative '../models'
  2. require 'scraperwiki'
  3. require 'sequel'
  4. load '_config.rb'
  5. require 'pp'
  6. class Object
  7. def to_hash
  8. h = {}
  9. instance_variables.each do |var|
  10. h[var.to_s.delete('@')] = instance_variable_get(var)
  11. end
  12. # Remove DataMapper-specific keys, which start with an underscore
  13. h.keys.each do |k|
  14. h.delete(k) if k.match(/^_/)
  15. end
  16. h
  17. end
  18. end
  19. DB = Sequel.connect(ENV['DATABASE_URL'])
  20. DB[:polls].each { |o| ScraperWiki.save_sqlite([:district_id, :election_id], o.to_hash, 'polls') }
  21. DB[:candidates].each { |o| ScraperWiki.save_sqlite([:id], o.to_hash, 'candidates') }
  22. DB[:candidacies].each { |o| ScraperWiki.save_sqlite([:id], o.to_hash, 'candidacies') }
  23. DB[:deleted_candidates].each { |o| ScraperWiki.save_sqlite([:old_candidate_id], o.to_hash, 'deleted_candidates') }
  24. DB[:elections].each { |o| ScraperWiki.save_sqlite([:id], o.to_hash, 'elections') }
  25. DB[:districts].each { |o| ScraperWiki.save_sqlite([:id], o.to_hash, 'districts') }
  26. DB[:bodies].each { |o| ScraperWiki.save_sqlite([:id], o.to_hash, 'bodies') }
  27. DB[:parties].each { |o| ScraperWiki.save_sqlite([:id], o.to_hash, 'parties') }