En regardant le site des Godillots, je me demandais si c'était possible de récupérer en direct les informations sur le site de l'Assemblée Nationale sans trop se prendre la tête (sans passer 2h sur un #$* parsing par exemple).

Une constatation, le site ne permet pas d'avoir, d'un seul bloc, les informations relatives aux interventions séances et commissions, les propositions de lois, etc... d'un simple coup d'oeil. Et on comprendrait pourquoi: on constaterait assez rapidement que beaucoup serait proche du zéro.

Voici donc un script écrit à l'arrache pour récupérer ce genre d'info pour l'ensemble des députés de l'Assemblée Nationale.

#!/bin/bash
# License BSD - Benjamin GIGON / Prae

function get_info {
    local DEPUTEID=$1
    local DOCTYPE=$2
    lynx -source "http://recherche2.assemblee-nationale.fr/resultats_tribun.jsp?id_auteur=${DEPUTEID}&legislature=13&typedoc=${DOCTYPE}"  \
        | grep '<span class="nbres">' \
        | html2text \
        | sed 's/^[[:space:]]*\(.*\)[[:space:]]*$/\1/' \
        | sed -e "s/ /+/g" \
        | bc
}
function get_listing {
    lynx "http://www.assemblee-nationale.fr/13/tribun/xml/liste_alpha.asp" -dump \
        | grep "fiches_id" \
        | awk '{ print $2 }' 
}
function get_name {
    local DEPUTEID=$1
    lynx -source "http://www.assemblee-nationale.fr/13/tribun/fiches_id/${DEPUTEID}.asp" \
        | grep -rs "<title>" \
        | awk -F':' '{ print $2 }' \
        | html2text
}

echo ";ID;Nom Depute;Interventions Seances;Interventions Commissions;         Rapports Informations;Propositions Lois;" 2> /dev/tty
echo "Nombre total:`get_listing | wc -l`" 1> /dev/tty 
get_listing | while read LINK;
do
    DEPUTE_ID=`basename $LINK .asp`;
    DEPUTE_NAME=`get_name ${DEPUTE_ID}`
    INTERVENTION_SEANCES=`get_info "${DEPUTE_ID}" "ComptesRendusIntegraux"`
    INTERVENTION_COMMISSIONS=`get_info "${DEPUTE_ID}" "ComptesRendusReunions"`
    RAPPORTS_INFO=`get_info "${DEPUTE_ID}" "Rapports"`
    PROPOSITIONS_LOIS=`get_info "${DEPUTE_ID}" "PropositionsLoi"`
    echo ";${DEPUTE_ID};${DEPUTE_NAME};${INTERVENTION_SEANCES};         ${INTERVENTION_COMMISSIONS};${RAPPORTS_INFO};${PROPOSITIONS_LOIS};" 2> /dev/tty

    let index=${index}+1;
    printf "Processing: #%d\r" ${index} 1> /dev/tty
done;
Je vous recommande de télécharger le script ici: Download

Utilisation simpliste, il suffit de lancer le script comme-cela:

$ ./get_deputes_listing.sh > listing.csv

L'output sur le canal de sortie "normal" est le contenu CSV, vous pourrez l'importez dans OpenOffice sans difficulté (il suffit juste de prendre comme caractère de séparation, le point virgule et encodage ISO-8859-1). En output terminal, vous aurez des informations sur le processing en cours.

Côté Terminal:
$ ./get_deputes_listing.sh > listing.csv
Nombre total:577
Processing: #7
Côté fichier CSV:
$ cat /tmp/listing.csv
;ID;Nom Depute;Interventions Seances;Interventions Commissions;Rapports Informations;Propositions Lois;
;226; M. Jean-Pierre Abelin;7;2;2;11;
;267457; M. Élie Aboud;10;4;;39;
;230; M. Bernard Accoyer;2;17;1;3;
;267695; Mme Patricia Adam;14;24;1;23;
;236; M. Manuel Aeschlimann;9;3;2;28;
;243; M. Yves Albarello;21;34;2;50;
;253; M. Alfred Almont;9;14;4;38;

Un petit output des députés de l'Assemblée Nationale pour Avril 2009: Download