republique

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

commit 73e8d8c265ada79fcfad6ecde5110a9e114700ad
parent 1fb48a6363190f00e8677b1556c53391fb5d2038
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Thu, 15 Oct 2015 12:19:41 +0100

refactor, add generation time

Diffstat:
maketable.sh | 90+++++++++++++++++++++++++++++++++----------------------------------------------
1 file changed, 38 insertions(+), 52 deletions(-)

diff --git a/maketable.sh b/maketable.sh @@ -3,56 +3,42 @@ # parse TSV $1 and generate report in $2 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>" - -cat head >$2/prop_pos.html -echo "<h1>Propositions par votes positifs décroissants</h1>" >> $2/prop_pos.html -echo "<table>" >> $2/prop_pos.html -echo "$HEADER" >> $2/prop_pos.html -grep '^opinion/[0-9]*\s' "$1" | sed 's_^opinion/__' | - sort -k3,3nr | ./escape.sh | - awk -f ./fmt.awk >> $2/prop_pos.html -echo "</table></body></html>" >> $2/prop_pos.html - -cat head >$2/prop_tot.html -echo "<h1>Propositions par votes totaux décroissants</h1>" >> $2/prop_tot.html -echo "<table>" >> $2/prop_tot.html -echo "$HEADER" >> $2/prop_tot.html -grep '^opinion/[0-9]*\s' "$1" | sed 's_^opinion/__' | - sort -k6,6nr | ./escape.sh | - awk -f ./fmt.awk >> $2/prop_tot.html -echo "</table></body></html>" >> $2/prop_tot.html - - -cat head >$2/modi_pos.html -echo "<h1>Modifications par votes positifs décroissants</h1>" >> $2/modi_pos.html -echo "<table>" >> $2/modi_pos.html -echo "$HEADER" >> $2/modi_pos.html -grep '^opinion/[0-9]*/version/[0-9]*\s' "$1" | sed 's_^[^\t]*/__' | - sort -k3,3nr | - ./escape.sh | - awk -f ./fmt.awk \ - >> $2/modi_pos.html -echo "</table></body></html>" >> $2/modi_pos.html - -cat head >$2/modi_tot.html -echo "<h1>Modifications par votes totaux décroissants</h1>" >> $2/modi_tot.html -echo "<table>" >> $2/modi_tot.html -echo "$HEADER" >> $2/modi_tot.html -grep '^opinion/[0-9]*/version/[0-9]*\s' "$1" | sed 's_^[^\t]*/__' | - sort -k6,6nr | - ./escape.sh | - awk -f ./fmt.awk \ - >> $2/modi_tot.html -echo "</table></body></html>" >> $2/modi_tot.html - - -cat head >$2/argu_pos.html -echo "<h1>Arguments par votes décroissants</h1>" >> $2/argu_pos.html -echo "<table>" >> $2/argu_pos.html -echo "$HEADER" >> $2/argu_pos.html -grep '^[^ ]*/argument/' "$1" | sed 's_^[^\t]*/__' | sort -k3,3nr | - ./escape.sh | - awk -f ./fmt.awk \ - >> $2/argu_pos.html -echo "</table></body></html>" >> $2/argu_pos.html +OUTDIR="$2" +TSV="$1" + +function onetable() { + TITLE="$1" + OUTPUT="$2" + SORT="$3" + REGEXP="$4" + SED="$5" + FILE="$OUTDIR/${OUTPUT}.html" + + cat head > "$FILE" + echo "<h1></h1>" >> "$FILE" + echo "<p>Generated on: `date`</p>" >> "$FILE" + echo "<table>" >> "$FILE" + echo "$HEADER" >> "$FILE" + grep "$REGEXP" "$TSV" | sed "$SED" | + sort -k$SORT | ./escape.sh | + awk -f ./fmt.awk >> "$FILE" + echo "</table>" >> "$FILE" + echo "</body></html>" >> "$FILE" +} + +onetable "Propositions par votes positifs décroissants" prop_pos \ + "3,3nr" '^opinion/[0-9]*\s' \ + 's_^opinion/__' +onetable "Propositions par votes totaux décroissants" prop_tot \ + "6,6nr" '^opinion/[0-9]*\s' \ + 's_^opinion/__' +onetable "Modifications par votes positifs décroissants" modi_pos \ + "3,3nr" '^opinion/[0-9]*/version/[0-9]*\s' \ + 's_^opinion/[0-9]*/version/__' +onetable "Modifications par votes totaux décroissants" modi_tot \ + "6,6nr" '^opinion/[0-9]*/version/[0-9]*\s' \ + 's_^opinion/[0-9]*/version/__' +onetable "Arguments par votes décroissants" argu_pos \ + "3,3nr" '^opinion/[0-9]*/version/[0-9]*/argument' \ + 's_^opinion/[0-9]*/version/[0-9]*/argument/__'