Showing 1 changed files with 12 additions and 13 deletions
+12 -13
analyse-votes-AN
... ...
@@ -5,7 +5,7 @@ prenom=$2
5 5
 nom=$3
6 6
 groupe_ref=${4:-GDR}
7 7
 
8
-declare -A groupes lrem_votes gdr_votes
8
+declare -A groupes cible_votes ref_votes
9 9
 groupes[LREM]='Groupe La République en Marche'
10 10
 groupes[LR]='Groupe Les Républicains'
11 11
 groupes[MODEM]='Groupe du Mouvement Démocrate et apparentés'
... ...
@@ -28,7 +28,6 @@ else
28 28
 fi
29 29
 
30 30
 tempfile="/dev/shm/scrutin"
31
-result="/dev/shm/comparaisons-$groupe"
32 31
 
33 32
 typevotes="Pour Contre Abstention Non-votants"
34 33
 
... ...
@@ -40,32 +39,32 @@ else
40 39
     result="/dev/shm/comparaisons $groupe avec $groupe_ref"
41 40
 fi
42 41
 
43
-echo -n 'scrutin;date;titre;adoption;' > $result
42
+echo -n 'scrutin;date;titre;adoption;' > "$result"
44 43
 for typevote in $typevotes; do
45 44
     for groupe in "$cible" $groupe_ref; do
46 45
         echo -n "$typevote - ${groupe};" >> "$result"
47 46
     done
48 47
 done
49
-echo >> $result
48
+echo >> "$result"
50 49
 
51 50
 last=$(wget -qO- 'http://www2.assemblee-nationale.fr/scrutins/liste/(legislature)/15/(type)/TOUS/(idDossier)/TOUS' | sed -rn 's,^.*<td class="denom">(.+)</td>.*$,\1,p' | head -1)
52 51
 for scrutin in $(seq $last); do
53
-    wget -qO $tempfile "http://www2.assemblee-nationale.fr/scrutins/detail/(legislature)/15/(num)/$scrutin"
52
+    wget -qO- $tempfile "http://www2.assemblee-nationale.fr/scrutins/detail/(legislature)/15/(num)/$scrutin" > $tempfile
54 53
 
55
-    title=$(sed -rn '/Analyse du scrutin n° '$scrutin'/n; s,^.*<h3 class="president-title">(.+).</h3>,\1,p' $tempfile)
54
+    title=$(sed -rn '/Analyse du scrutin n° '$scrutin'/n; s,^.*<h3 class="president-title">(.+).</h3>,\1,p' $tempfile | sed 's/;//g; s/[ \t][ \t]+/ /g')
56 55
     date=$(sed -rn 's,^.*<h1 class="">Analyse du scrutin n° '$scrutin'<br/>(.+) </h1>,\1,p' $tempfile)
57 56
     grep -q "L'assemblée nationale a adopté." $tempfile && adoption='oui' || adoption='non'
58 57
 
59
-    echo -n "$scrutin;$date;$title;$adoption;" >> $result
58
+    echo -n "$scrutin;$date;$title;$adoption;" >> "$result"
60 59
 
61
-    unset lrem_votes[*] gdr_votes[*]
60
+    unset cible_votes[*] ref_votes[*]
62 61
     for typevote in $typevotes; do
63
-        lrem_votes[$typevote]=$(sed -rn "${groupes[$groupe]}p" $tempfile | sed -rn '/<p class="typevote">'${typevote}':/,/<.div>/p' | sed 's,</li>,\n,g' | grep -c "${prenom}&nbsp;<b>${nom}")
64
-        echo -n "${lrem_votes[$typevote]};" >> $result
65
-        gdr_votes[$typevote]=$(sed -rn  "${groupes[$groupe_ref]}p"  $tempfile | sed -rn '/<p class="typevote">'${typevote}':/,/<.div>/p' | sed 's,</li>,\n,g' | grep -c '&nbsp;<b>')
66
-        echo -n "${gdr_votes[$typevote]};" >> $result
62
+        cible_votes[$typevote]=$(sed -rn "${groupes[$groupe]}p" $tempfile | sed -rn '/<p class="typevote">'${typevote}':/,/<.div>/p' | sed 's,</li>,\n,g' | grep -c "${prenom}&nbsp;<b>${nom}")
63
+        echo -n "${cible_votes[$typevote]};" >> "$result"
64
+        ref_votes[$typevote]=$(sed -rn  "${groupes[$groupe_ref]}p"  $tempfile | sed -rn '/<p class="typevote">'${typevote}':/,/<.div>/p' | sed 's,</li>,\n,g' | grep -c '&nbsp;<b>')
65
+        echo -n "${ref_votes[$typevote]};" >> "$result"
67 66
     done
68
-    echo >> $result
67
+    echo >> "$result"
69 68
 
70 69
     rm $tempfile
71 70
 done