republique

helper scripts for www.republique-numerique.fr
git clone https://a3nm.net/git/republique/
Log | Files | Refs | README

maketable.sh (1558B)


      1 #!/bin/bash
      2 
      3 DIR="$( cd "$( dirname "$0" )" && pwd )"
      4 cd "$DIR"
      5 
      6 # parse TSV $1 and generate report in $2
      7 
      8 HEADER="<tr><th>id</th><th>auteur</th><th>vote_pour</th><th>vote_mitige</th><th>vote_contre</th><th>vote_tot</th><th>prop</th>"
      9 OUTDIR="$2"
     10 TSV="$1"
     11 
     12 function onetable() {
     13   TITLE="$1"
     14   OUTPUT="$2"
     15   SORT="$3"
     16   REGEXP="$4"
     17   SED="$5"
     18   FILE="$OUTDIR/${OUTPUT}.html"
     19 
     20   cat head > "$FILE"
     21   echo "<h1></h1>" >> "$FILE"
     22   echo "<p>Generated on: `date`</p>" >> "$FILE"
     23   echo "<p>(This is the date when generation was <em>finished</em>," >> "$FILE"
     24   echo "the data may have been collected up to around 30 min before.)</p>" >> "$FILE"
     25   echo "<table>" >> "$FILE"
     26   echo "$HEADER" >> "$FILE"
     27   grep "$REGEXP" "$TSV" | sed "$SED" |
     28     sort -k$SORT | ./escape.sh |
     29     awk -f ./fmt.awk >> "$FILE"
     30   echo "</table>" >> "$FILE"
     31   echo "</body></html>" >> "$FILE"
     32 }
     33 
     34 onetable "Propositions par votes positifs décroissants" prop_pos \
     35   "3,3nr" '^opinion/[0-9]*\s' \
     36   's_^opinion/__'
     37 onetable "Propositions par votes totaux décroissants" prop_tot \
     38   "6,6nr" '^opinion/[0-9]*\s' \
     39   's_^opinion/__'
     40 onetable "Modifications par votes positifs décroissants" modi_pos \
     41   "3,3nr" '^opinion/[0-9]*/version/[0-9]*\s' \
     42   's_^opinion/[0-9]*/version/__'
     43 onetable "Modifications par votes totaux décroissants" modi_tot \
     44   "6,6nr" '^opinion/[0-9]*/version/[0-9]*\s' \
     45   's_^opinion/[0-9]*/version/__'
     46 onetable "Arguments par votes décroissants" argu_pos \
     47   "3,3nr" '^opinion/[0-9]*/version/[0-9]*/argument' \
     48   's_^opinion/[0-9]*/version/[0-9]*/argument/__'
     49