Share Pastebin
Guest
Public paste!

absence-AN

By: a guest | Apr 19th, 2009 | Syntax: Bash | Size: 1.50 KB | Hits: 229 | Expires: Never
Copy text to clipboard
  1. #!/bin/bash
  2. # License BSD - Benjamin GIGON / Prae
  3.  
  4. function get_info {
  5.         local DEPUTEID=$1
  6.         local DOCTYPE=$2
  7.         lynx -source "http://recherche2.assemblee-nationale.fr/resultats_tribun.jsp?id_auteur=${DEPUTEID}&legislature=13&typedoc=${DOCTYPE}"  \
  8.                 | grep '<span class="nbres">' \
  9.                 | html2text \
  10.                 | sed 's/^[[:space:]]*\(.*\)[[:space:]]*$/\1/' \
  11.                 | sed -e "s/ /+/g" \
  12.                 | bc
  13. }
  14. function get_listing {
  15.         lynx "http://www.assemblee-nationale.fr/13/tribun/xml/liste_alpha.asp" -dump \
  16.                 | grep "fiches_id" \
  17.                 | awk '{ print $2 }'
  18. }
  19. function get_name {
  20.         local DEPUTEID=$1
  21.         lynx -source "http://www.assemblee-nationale.fr/13/tribun/fiches_id/${DEPUTEID}.asp" \
  22.                 | grep -rs "<title>" \
  23.                 | awk -F':' '{ print $2 }' \
  24.                 | html2text
  25. }
  26.  
  27. echo ";ID;Nom Depute;Interventions Seances;Interventions Commissions;Rapports Informations;Propositions Lois;" 2> /dev/tty
  28. echo "Nombre total:`get_listing | wc -l`" 1> /dev/tty
  29. get_listing | while read LINK;
  30. do
  31.         DEPUTE_ID=`basename $LINK .asp`;
  32.         DEPUTE_NAME=`get_name ${DEPUTE_ID}`
  33.         INTERVENTION_SEANCES=`get_info "${DEPUTE_ID}" "ComptesRendusIntegraux"`
  34.         INTERVENTION_COMMISSIONS=`get_info "${DEPUTE_ID}" "ComptesRendusReunions"`
  35.         RAPPORTS_INFO=`get_info "${DEPUTE_ID}" "Rapports"`
  36.         PROPOSITIONS_LOIS=`get_info "${DEPUTE_ID}" "PropositionsLoi"`
  37.         echo ";${DEPUTE_ID};${DEPUTE_NAME};${INTERVENTION_SEANCES};${INTERVENTION_COMMISSIONS};${RAPPORTS_INFO};${PROPOSITIONS_LOIS};" 2> /dev/tty
  38.  
  39.         let index=${index}+1;
  40.         printf "Processing: #%d\r" ${index} 1> /dev/tty
  41. done;