Showing 1 changed files with 9 additions and 7 deletions
+9 -7
analyse-votes-AN
... ...
@@ -376,6 +376,12 @@ function save_database () {
376 376
     fi
377 377
 }
378 378
 
379
+function dernier_scrutin_public () {
380
+    wget -qO- 'http://www2.assemblee-nationale.fr/scrutins/liste/(legislature)/15/(type)/TOUS/(idDossier)/TOUS' \
381
+            | sed -rn 's,^.*<td class="denom">(.+)</td>.*$,\1,p' \
382
+            | head -1
383
+}
384
+
379 385
 trap save_database EXIT
380 386
 
381 387
 true_flag=$(mktemp --dry-run XXXXX)
... ...
@@ -532,10 +538,7 @@ if test "$periode" = $true_flag; then
532 538
     test -z "$first" && echo "date de début inconnue: ${periode_value#*:}" >&2 && rm -f $in_ram_database && exit 1
533 539
     test -z "$last" && echo "date de fin inconnue: ${periode_value%:*}" >&2 && rm -f $in_ram_database && exit 1
534 540
 elif test "$dossier" != $true_flag; then
535
-    test -z "$last" && last=$(wget -qO- 'http://www2.assemblee-nationale.fr/scrutins/liste/(legislature)/15/(type)/TOUS/(idDossier)/TOUS' \
536
-            | sed -rn 's,^.*<td class="denom">(.+)</td>.*$,\1,p' \
537
-            | head -1)
538
-
541
+    test -z "$last" && last=$(dernier_scrutin_public)
539 542
     test -z "$first" && first=1
540 543
 fi
541 544
 
... ...
@@ -546,9 +549,7 @@ fi
546 549
 
547 550
 if test "$db_update_only" = $true_flag; then
548 551
     unset first last
549
-    last=$(wget -qO- 'http://www2.assemblee-nationale.fr/scrutins/liste/(legislature)/15/(type)/TOUS/(idDossier)/TOUS' \
550
-            | sed -rn 's,^.*<td class="denom">(.+)</td>.*$,\1,p' \
551
-            | head -1)
552
+    last=$(dernier_scrutin_public)
552 553
     update_database
553 554
     exit
554 555
 fi
... ...
@@ -581,6 +582,7 @@ if test "$depute" = $true_flag; then
581 582
 fi
582 583
 
583 584
 if test "$dossier" = $true_flag; then
585
+    last=$(dernier_scrutin_public)
584 586
     if test -z "$dossier_value"; then
585 587
         IFS=$'\n'
586 588
         select dossier in $(sqlite_request "select url from url" | sed 's,^.*/dossiers/,,; s/_/ /g; s/.asp$//'); do