public
Fork of bruno/openaustralia-parser
Description: Parser component for Open Australia
Homepage: http://openaustralia.org
Clone URL: git://github.com/mlandauer/openaustralia-parser.git
openaustralia-parser / create_patch.rb
100755 46 lines (35 sloc) 1.174 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
# Create a patch easily for a particular date
 
$:.unshift "#{File.dirname(__FILE__)}/lib"
 
require 'environment'
require 'optparse'
require 'date'
require 'people_csv_reader'
require 'hansard_parser'
 
OptionParser.new do |opts|
  opts.banner = <<EOF
Usage: create-patch.rb <reps|senate> <year.month.day>
EOF
end.parse!
 
if ARGV.size != 2
  puts "Wrong number of parameters"
  exit
end
    
if ARGV[0] == "reps"
  house = House.representatives
elsif ARGV[0] == "senate"
  house = House.senate
else
  puts "Expected 'reps' or 'senate' for first parameter"
  exit
end
 
date = Date.parse(ARGV[1])
 
# For the time being just edit the representatives
 
people = PeopleCSVReader.read_members
parser = HansardParser.new(people)
 
# First check that there isn't already a patch file
patch_file_path = "#{File.dirname(__FILE__)}/data/patches/#{house}.#{date}.xml.patch"
 
File.open("original.xml", "w") {|f| f << parser.unpatched_hansard_xml_source_data_on_date(date, house)}
File.open("patched.xml", "w") {|f| f << parser.hansard_xml_source_data_on_date(date, house)}
system("mate --wait patched.xml")
system("diff -u original.xml patched.xml > #{patch_file_path}")