1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | $file = $url = shift; |
---|
4 | #use HTML::TokeParser; |
---|
5 | $url =~ s/^[^\/]+\///; |
---|
6 | $url =~ s/_/\//g; |
---|
7 | $source = $url; |
---|
8 | |
---|
9 | if ($url =~ /\/(\d+)-(\d+)\//) { |
---|
10 | $session = '20'.$1.'20'.$2; |
---|
11 | } |
---|
12 | |
---|
13 | open(FILE, $file) ; |
---|
14 | @string = <FILE>; |
---|
15 | $string = "@string"; |
---|
16 | close FILE; |
---|
17 | |
---|
18 | $string =~ s/<\/?b>/|/g; |
---|
19 | $string =~ s/<\/?i>/\//g; |
---|
20 | $string =~ s/\r//g; |
---|
21 | |
---|
22 | $mois{'janvier'} = '01'; |
---|
23 | $mois{'février'} = '02'; |
---|
24 | $mois{'mars'} = '03'; |
---|
25 | $mois{'avril'} = '04'; |
---|
26 | $mois{'mai'} = '05'; |
---|
27 | $mois{'juin'} = '06'; |
---|
28 | $mois{'juillet'} = '07'; |
---|
29 | $mois{'août'} = '08'; |
---|
30 | $mois{'septembre'} = '09'; |
---|
31 | $mois{'octobre'} = '10'; |
---|
32 | $mois{'novembre'} = '11'; |
---|
33 | $mois{'décembre'} = '12'; |
---|
34 | |
---|
35 | |
---|
36 | #utf8::decode($string); |
---|
37 | # |
---|
38 | #$p = HTML::TokeParser->new(\$string); |
---|
39 | # |
---|
40 | #while ($t = $p->get_tag('p', 'h1', 'h5')) { |
---|
41 | # print "--".$p->get_text('/'.$t->[0])."\n"; |
---|
42 | #} |
---|
43 | # |
---|
44 | #exit; |
---|
45 | $cpt = 0; |
---|
46 | sub checkout { |
---|
47 | if ($#presents <= 0) { |
---|
48 | print STDERR "$source: Pas de présent trouvé\n"; |
---|
49 | return ; |
---|
50 | } |
---|
51 | foreach $depute (@presents) { |
---|
52 | $depute =~ s/[\/<\|]//g; |
---|
53 | $depute =~ s/^\s*M[me\.]+\s+//; |
---|
54 | $depute =~ s/\s+$//; |
---|
55 | print '{"reunion": "'.$date.'", "session": "'.$heure.'", "commission": "'.$commission.'", "depute": "'.$depute.'", "source": "'.$source.'"}'."\n"; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | $string =~ s/\r//g; |
---|
60 | $string =~ s/ / /g; |
---|
61 | $string =~ s/’/'/g; |
---|
62 | $string =~ s/œ|œ+/oe/g; |
---|
63 | $string =~ s/\|(\W+)\|/$1/g; |
---|
64 | $string =~ s/ission d\W+information/ission d'information/gi; |
---|
65 | $string =~ s/à l\W+aménagement /à l'aménagement /gi; |
---|
66 | $majIntervenant = 0; |
---|
67 | $body = 0; |
---|
68 | $present = 0; |
---|
69 | $string =~ s/<br>\n//gi; |
---|
70 | |
---|
71 | # Le cas de <ul> qui peut faire confondre une nomination à une intervention : |
---|
72 | #on vire les paragraphes contenus et on didascalise |
---|
73 | |
---|
74 | |
---|
75 | $string =~ s/<\/?ul>//gi; |
---|
76 | |
---|
77 | #print $string; exit; |
---|
78 | |
---|
79 | foreach $line (split /\n/, $string) |
---|
80 | { |
---|
81 | if ($line =~ /<body[^>]*>/) { |
---|
82 | $body = 1; |
---|
83 | } |
---|
84 | next unless ($body); |
---|
85 | if ($line =~ /\<[a]/i) { |
---|
86 | if ($line =~ /<a name=["']([^"']+)["']/) { |
---|
87 | $source = $url."#$1"; |
---|
88 | }elsif($line =~ /<a[^>]+>([^<]+)</) { |
---|
89 | $test = $1; |
---|
90 | if (!$commission && $test =~ /Commission|mission/) { |
---|
91 | $test =~ s/ Les comptes rendus de la //; |
---|
92 | $test =~ s/^ +//; |
---|
93 | if ($test !~ /spéciale$/i) { |
---|
94 | $commission = $test; |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | if ($line =~ /<h[1-9]+/i) { |
---|
100 | if (!$date && $line =~ /SOMdate|\"seance\"|h2/) { |
---|
101 | if ($line =~ /SOMdate|Lundi|Mardi|Mercredi|Jeudi|Vendredi|Samedi|Dimanche/i) { |
---|
102 | if ($line =~ /\w+\s+(\d+)[erme]*\s+([^\s\d]+)\s+(\d+)/i) { |
---|
103 | $date = sprintf("%04d-%02d-%02d", $3, $mois{lc($2)}, $1); |
---|
104 | } |
---|
105 | } |
---|
106 | }elsif ($line =~ /SOMseance|"souligne_cra"/i) { |
---|
107 | if ($line =~ /(\d+)\s*(h|heures?)\s*(\d*)/i) { |
---|
108 | $heure = sprintf("%02d:%02d", $1, $3 || "00"); |
---|
109 | } |
---|
110 | }elsif(!$commission && $line =~ /groupe|commission|mission|délégation|office|comité/i) { |
---|
111 | if ($line =~ /[\>\|]\s*((Groupe|Com|Miss|Délé|Offic)[^\>\|]+)[\<\|]/) { |
---|
112 | $commission = $1; |
---|
113 | $commission =~ s/\s*$//; |
---|
114 | } |
---|
115 | }elsif($line =~ /SOMnumcr/i) { |
---|
116 | if ($line =~ /\s0*(\d+)/ && $1 > 1) { |
---|
117 | $cpt = $1*1000000; |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | if ($present) { |
---|
122 | $line =~ s/<[^>]+>//gi; |
---|
123 | $line =~ s/&[^;]*;/ /gi; |
---|
124 | if ($line =~ s/\/?(Présents|Assistai(en)?t également à la réunion)\W+//) { |
---|
125 | push @presents, split /, /, $line; #/ |
---|
126 | } |
---|
127 | } |
---|
128 | if ($line =~ /[>\|\/](Membres? présents? ou excusés?|Présences? en réunion)[<\|\/]/ || $line =~ /[>\/\|]La séance est levée/) { |
---|
129 | $present = 1; |
---|
130 | } |
---|
131 | } |
---|
132 | checkout(); |
---|