...
|
...
|
@@ -1,5 +1,7 @@
|
1
|
1
|
#!/bin/bash
|
2
|
2
|
|
|
3
|
+set -e
|
|
4
|
+
|
3
|
5
|
for tool in sqlite3 getopt md5sum mktemp; do
|
4
|
6
|
which $tool > /dev/null 2>&1 || {
|
5
|
7
|
echo missing tool $tool
|
...
|
...
|
@@ -89,13 +91,24 @@ function update_database () {
|
89
|
91
|
|
90
|
92
|
title=$(sed -rn '/<h1 class="">Analyse du scrutin n° '$scrutin'/n; s,^.*<h3 class="president-title">(.+).</h3>,\1,p' $tempfile \
|
91
|
93
|
| sed "s/;//g; s/[ \t][ \t]+/ /g; s/^Scrutin public sur *//; s/^l[ae']s* *//")
|
92
|
|
- date=$(sed -rn 's,^.*<h1 class="">Analyse du scrutin n° '$scrutin'<br/>(.+) </h1>,\1,p' $tempfile)
|
93
|
|
- adoption=$(sed -rn 's,^.*<p class="annonce"><span class="annoncevote">(.+).</span></p>.*$,\1,p' $tempfile)
|
94
|
|
- test -n "$title" -a -n "$date" -a -n "$adoption" || {
|
|
94
|
+ eval $(sed -rn '
|
|
95
|
+ s,^.*<h1 class="">Analyse du scrutin n° '$scrutin'<br/>(.+) </h1>,date="\1",p
|
|
96
|
+ s,^.*<p class="annonce"><span class="annoncevote">(.+).</span></p>.*$,adoption="\1",p
|
|
97
|
+ s,^.*<p .*class="repartitionvotes.*Pour l.adoption :.+>([0-9]+)<.*$,pour=\1,p
|
|
98
|
+ s,^.*<p .*class="repartitionvotes.*Contre :.+>([0-9]+)<.*$,contre=\1,p' $tempfile)
|
|
99
|
+ test -n "$title" -a -n "$date" || {
|
95
|
100
|
echo "erreur dans la récupération du scrutin $scrutin"
|
96
|
101
|
exit 1
|
97
|
102
|
}
|
98
|
|
- grep -q 'e a a' <<< "$adoption" && adoption=1 || adoption=0
|
|
103
|
+ if test -n "$adoption"; then
|
|
104
|
+ grep -q 'e a a' <<< "$adoption" && adoption=1 || adoption=0
|
|
105
|
+ else
|
|
106
|
+ if test $pour -gt $contre; then
|
|
107
|
+ adoption=1
|
|
108
|
+ elif test $contre -gt $pour; then
|
|
109
|
+ adoption=0
|
|
110
|
+ fi
|
|
111
|
+ fi
|
99
|
112
|
|
100
|
113
|
url=$(awk -F'|' "/^$scrutin\|/{print \$2}" "$url_database")
|
101
|
114
|
id_url=$(sqlite_request "select id from url where url is '$url'")
|
...
|
...
|
@@ -105,6 +118,7 @@ function update_database () {
|
105
|
118
|
fi
|
106
|
119
|
|
107
|
120
|
sqlite_request "insert into scrutins values ($scrutin, '$date', \"${title//\"}\", $adoption, ${id_url:-0})"
|
|
121
|
+ unset adoption pour contre
|
108
|
122
|
|
109
|
123
|
for v in $(sqlite_request "select * from votes"); do
|
110
|
124
|
for g in $(sqlite_request "select id,nom from groupes"); do
|