Commit 56d6eebf authored by Michael Witrant's avatar Michael Witrant

commited old files

parent 3fe64c78
source "http://rubygems.org"
gem "nokogiri"
gem 'htmldiff'
GEM
remote: http://rubygems.org/
specs:
htmldiff (0.0.1)
nokogiri (1.5.2)
PLATFORMS
ruby
DEPENDENCIES
htmldiff
nokogiri
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env ruby
# encoding: utf-8
# Pour lancer le script il faut ruby, rubygems et les gems nokogiri et htmldiff
require 'rubygems'
require "bundler/setup"
require 'nokogiri'
require 'htmldiff'
require 'erb'
data = File.read("LQDN_20120503_amendments_ITRE_ACTA_report.txt")
sections = data.scan(%r(<Amend>.+?</Amend>)m)
Amendment = Struct.new :num, :note, :color, :commission_rows, :amendement_rows, :members, :article
include HTMLDiff
class Amendment
Template = ERB.new File.read('template.erb'), nil, '-'
def format
Template.result(binding)
end
def rows
[commission_rows.size, amendement_rows.size].max
end
end
amendments = sections.map do |xml|
doc = Nokogiri::XML(xml)
num, note = doc.css('NumAm').text.split(' ', 2)
num = num.to_i
note.gsub!(/\s/, '') if note
color = case note.to_s.gsub(/[^-+]/, '')
when "--"
"red"
when "-"
"IndianRed"
when "++", "+++"
"green"
when "+"
"lightgreen"
when ""
"lightgrey"
else
raise "Invalid note: #{note.inspect}"
end
infos = xml.scan(%r(Proposal for a decision\nAmendment\n(.+)\nOr.)m).first
raise "No info found" unless infos
infos = infos.first.split(/\n/)
commission_rows = []
amendement_rows = []
infos.each_slice(2) do |commission, amendment|
commission = commission.to_s
amendment = amendment.to_s
commission_rows << diff(commission, amendment).to_s.gsub(%r(<ins class=".+?">.+?</ins>), "").gsub(%r(<del class=".+?">(.+?)</del>), "'''\\1'''")
amendement_rows << diff(commission, amendment).to_s.gsub(%r(<del class=".+?">.+?</del>), "").gsub(%r(<ins class=".+?">(.+?)</ins>), "'''\\1'''")
end
members = doc.css('Members').text
article = doc.css('Article').text
Amendment.new num, note, color, commission_rows, amendement_rows, members, article
end
File.open "result.mediawiki", "w" do |f|
grouped = amendments.group_by { |am| (am.num - 1) / 10 }
grouped.keys.sort.each do |index|
ams = grouped[index].sort_by { |am| am.num }
first = ams.first.num
last = ams.last.num
f.puts "== Amendments #{first}#{last} =="
ams.each do |am|
f.puts am.format
end
f.puts
end
end
This diff is collapsed.
=== Amendment <%= num %><%= " " + note if note %> ===
{| border="1" style="border-spacing:0;" cellpadding="3"
|-
! colspan="2" style="background-color: <%= color %>;" |
Amendement <%= num %>
<br/>
<%= article %>
<br/>
<%= members %>
<br/>
<%= note %>
<% rows.times do |row| -%>
|-
|width="50%"|
<%= commission_rows[row] %>
|width="50%"|
<%= amendement_rows[row] %>
<% end -%>
|-
| colspan="2" |
Comments:
|}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment