X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=sidebyside;f=update.sh;h=008f716e732607204655ffd7e0529d44b21e99c0;hb=402755409e719a9e2cba7a9dcb1482b5834a3aa1;hp=27a9dd1fe476f16009fb0d94f0af5fa62eeccc86;hpb=a3d2a6533cb6aee29c48c8e1e08e4981c0c8829b;p=berlin-corona-table
diff --git a/update.sh b/update.sh
index 27a9dd1..008f716 100755
--- a/update.sh
+++ b/update.sh
@@ -1,22 +1,28 @@
#!/bin/sh
set -e
-CSV_URL=https://www.berlin.de/lageso/_assets/gesundheit/publikationen/corona/bezirkstabelle.csv
+CSV_URL=https://www.berlin.de/lageso/_assets/gesundheit/publikationen/corona/bezirkstabelle.csv
table_path=daily_infections_table.txt
# If we don't have a table file yet, we need to provide its header.
header=" CW FK Li MH Mi Ne Pa Re Sp SZ TS TK sum"
-if [ ! -f "${table_path}" ]; then
+if [ ! -f "${table_path}" ]; then
echo "${header}" > "${table_path}"
fi
-# Parse Lageso day table of new infections by district into new line for history table.
+# Parse Lageso day table of new infections by district into new line for history table.
today="$(date +%Y-%m-%d)"
curl "${CSV_URL}" \
| awk 'BEGIN { FS=";"; ORS=""; print "'${today}'" }; '\
-'!/^Bezirk/ { printf "%4d", $3 }; '\
-'END { printf "\n" }' "${filename}" >> "${table_path}"
+'!/^"Bezirk"/ { printf "%4d", $3 }; '\
+'END { printf "\n" }' "${filename}" >> "${table_path}"
# Write enhanced table output to directory served by web server.
-./enhance_table.py "${table_path}" txt > /var/www/html/berlin_corona.txt
-./enhance_table.py "${table_path}" html > /var/www/html/berlin_corona.html
+#
+# Use intermediate /tmp/ step so we don't overwrite a valid previous output with
+# the emptiness delivered to stdout on any error, before such an error would
+# kill this script due to "set -e".
+./enhance_table.py "${table_path}" html > /tmp/berlin_corona.html
+./enhance_table.py "${table_path}" txt > /tmp/berlin_corona.txt
+mv /tmp/berlin_corona.html /var/www/html/
+mv /tmp/berlin_corona.txt /var/www/html/