forked from openaustralia/openaustralia-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_patch.rb
executable file
·45 lines (35 loc) · 1.15 KB
/
create_patch.rb
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
#!/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}")