web: Allow publishing of donation stats.
authorWerner Koch <wk@gnupg.org>
Thu, 16 Oct 2014 19:33:32 +0000 (21:33 +0200)
committerWerner Koch <wk@gnupg.org>
Thu, 16 Oct 2014 19:33:32 +0000 (21:33 +0200)
* tools/append-to-donors.sh: Create donations summaray file.
* tools/mkkudos.sh: Add new template for this months donations.
* web/donate/kudos.org: Add a line wit the current donations.
--

This requires the latest payproc version.

tools/append-to-donors.sh
tools/mkkudos.sh
web/donate/kudos.org

index f1156c5..492ab32 100755 (executable)
@@ -16,6 +16,8 @@ SIGDELIM="-- "
 htdocs="/var/www/www/www.gnupg.org/htdocs"
 
 donors="$htdocs/donate/donors.dat"
+donations="$htdocs/donate/donations.dat"
+
 journal_dir="/var/log/payproc"
 LOCKFILE="$donors.lock"
 
@@ -28,7 +30,7 @@ if ! lockfile -l 7200 -r 2 $LOCKFILE; then
     echo "$pgm: another instance is still running"
     exit 0
 fi
-trap "rm -f $LOCKFILE" 0
+trap "rm -f $LOCKFILE $donors.tmp $donors.stamp" 0
 
 
 # Send a thank you mail
@@ -42,6 +44,7 @@ trap "rm -f $LOCKFILE" 0
 # Used scratch variables:
 #  upcurrency
 #  ineuro
+#  xamount
 #
 # FIXME: Clean message and name and use an appropriate encoding.
 #        The second mail should actually be encrypted.  In fact
@@ -53,8 +56,9 @@ send_thanks () {
     if [ "$upcurrency" = EUR ]; then
         ineuro=
     else
-        ineuro=" (about $euro EUR)"
+        ineuro=" (about $(echo $euro| awk '{print int($0 + 0.5)}') EUR)"
     fi
+    xamount="$(echo $amount| awk '{print int($0 + 0.5)}')"
     ( cat <<EOF
 From: donations@gnupg.org
 To: $xmail
@@ -66,7 +70,7 @@ X-Loop: gnupg-donations-thanks.gnupg.org
 
 Dear ${name:-Anonymous},
 
-we received $amount $upcurrency$ineuro as a donation for the GnuPG project.
+we received $xamount $upcurrency$ineuro as a donation to the GnuPG project.
 Your donation helps us to develop and maintain GnuPG and related software.
 
 Thank you.
@@ -113,6 +117,8 @@ lastline=$(echo $tmp | cut -d: -f2)
 [ -z "$lastdate" ] && lastdate=19700101
 [ -z "$lastline" ] && lastline=0
 
+
+[ -f "$donors".stamp ] && rm "$donors".stamp
 cat "$donors" > "$donors.tmp"
 find $journal_dir -type f -name 'journal-????????.log' -print \
      | sort | while read fname; do
@@ -131,15 +137,31 @@ find $journal_dir -type f -name 'journal-????????.log' -print \
             name=$(echo "$name" | tr \`\$: ...)
             message=$(echo "$message" | tr \`\$ ..)
             xmail=$(echo "$xmail" | tr \`\$ ..)
-            if [ -n "$name" ]; then
-               # Note that we removed colons from $name
-               echo "$jyear:$datestr:$name::$lnr:" >> "$donors.tmp"
-            fi
+            # Note that we removed colons from $name
+            echo "$jyear:$datestr:$name::$lnr:" >> "$donors.tmp"
+            touch "$donors".stamp
             send_thanks
          done
     fi
 done
-if ! mv "$donors.tmp" "$donors"; then
-  echo "$pgm: error updating $donors" >&2
-  exit 1
+
+# If we have any new records update the files.
+if [ -f "$donors".stamp ]; then
+
+  if ! mv "$donors.tmp" "$donors"; then
+    echo "$pgm: error updating $donors" >&2
+    exit 1
+  fi
+
+  if [ -f "$donations" ]; then
+    payproc-stat -u "$donations" -- > "$donations".tmp  \
+      $(find /var/log/payproc -type f -name 'journal-????????.log' -print|sort)
+    if ! mv "$donations".tmp "$donations"; then
+        echo "$pgm: error updating $donations" >&2
+        exit 1
+    fi
+  else
+    payproc-stat -u "$donations" -- > "$donations"  \
+      $(find /var/log/payproc -type f -name 'journal-????????.log' -print|sort)
+  fi
 fi
index f3625e0..3c42a8a 100755 (executable)
@@ -6,11 +6,25 @@ htdocs="/var/www/www/www.gnupg.org/htdocs"
 #htdocs="/home/wk/s/gnupg-doc/web"
 
 donors="$htdocs/donate/donors.dat"
+donations="$htdocs/donate/donations.dat"
 
 if [ ! -f "$donors" ]; then
   echo "mkkudos.sh: '$donors' not found" >&2;
   exit 1
 fi
+if [ ! -f "$donations" ]; then
+  echo "mkkudos.sh: '$donations' not found" >&2;
+  exit 1
+fi
+
+tmp=$(head -1 "$donations")
+monyear=$(echo "$tmp" | awk -F: 'BEGIN { m[1] = "January";
+      m[2] = "February"; m[3] = "March"; m[4] = "April"; m[5] = "May";
+      m[6] = "June"; m[7] = "July"; m[8] = "August"; m[9] = "September";
+      m[10] = "October"; m[11] = "November"; m[12] = "December"; }
+      {printf "%s %d", m[$2] , $1}')
+euro=$(echo "$tmp" | awk -F: '{printf "%d Euro", int($8 + 0.5)}')
+
 
 for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html; do
    [ "$file" -ot "$donors" ] || continue
@@ -22,17 +36,28 @@ for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html; do
    fi
    echo "processing $file" >&2
    [ -f "$file.tmp" ] && rm "$file.tmp"
-   awk -F: -v year=$year -v donors="$donors" <"$file"  >"$file.tmp" '
+   awk -F: -v year=$year -v donors="$donors" \
+           -v monyear="$monyear" -v euro="$euro" <"$file"  >"$file.tmp" '
      /<!--BEGIN-DONATIONS-->/ {indon=1; print; insert("") }
      /<!--END-DONATIONS-->/ {indon=0}
      /<!--BEGIN-DONATIONS_goteo13-->/ {indon=1; print; insert("goteo13") }
      /<!--END-DONATIONS_goteo13-->/ {indon=0}
+     /<!--INSERT-MONTH-DATE-->/ {
+           printf "<!--INSERT-MONTH-DATE--> %s\n", monyear;
+           next
+     }
+     /<!--INSERT-MONTH-EURO-->/ {
+           printf "<!--INSERT-MONTH-EURO--> %s\n", euro;
+           next
+     }
      !indon { print }
 
      function insert (tag) {
        while (getline < donors) {
          if ( $0 ~ /^(#.*)?$/ )
             continue;
+         if ( $3 == "" )
+            continue;
          if ($1==year && $4==tag) {
            printf "<li>%s</li>\n", $3
          }
index e3c4a46..fbee1a5 100644 (file)
 
 ** Donation summary
 
+#+HTML: <p>In
+#+HTML: <!--INSERT-MONTH-DATE-->
+#+HTML: we received
+#+HTML: <!--INSERT-MONTH-EURO-->
+#+HTML: of donations by credit card plus some more donations via Paypal.
+#+HTML: </p>
+
+
 | Year |   # |  \EUR | net \EUR |
 |      | <r> |   <r> |      <r> |
 |------+-----+-------+----------|