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.
 
 
 
 

24 lines
680 B

  1. # Convert ModernGov XML file to CSV
  2. # eg https://moderngov.sutton.gov.uk/mgWebService.asmx/GetElectionResults?lElectionId=15
  3. # The full API docs are at: https://moderngov.sutton.gov.uk/mgWebService.asmx
  4. require 'nokogiri'
  5. require 'csv'
  6. require 'pp'
  7. doc = File.open(ARGV.shift) { |f| Nokogiri::XML(f) }
  8. csv_string = CSV.generate do |csv|
  9. doc.search('candidates candidate').each do |cand|
  10. row = []
  11. row << cand.at('areatitle').inner_text
  12. row << cand.at('candidatename').inner_text
  13. row << cand.at('politicalpartytitle').inner_text
  14. row << cand.at('numvotes').inner_text.to_i
  15. row << cand.at('iselected').inner_text
  16. csv << row
  17. end
  18. end
  19. puts csv_string