X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=sidebyside;f=update.sh;h=ace8592a60902c614e510a2b6020621981b734f2;hb=0c72202485d4042624ee6523c0c751c73d031a7d;hp=a136185f923650da76b19cef6a7fd4f1b8d8d122;hpb=7c65171564d45767cac7ba903dd8206620943b2e;p=berlin-corona-table
diff --git a/update.sh b/update.sh
index a136185..ace8592 100755
--- a/update.sh
+++ b/update.sh
@@ -1,11 +1,28 @@
#!/bin/sh
+set -e
-# Parse Lageso day table of new infections by district into new line for history table.
+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
+ echo "${header}" > "${table_path}"
+fi
+
+# Parse Lageso day table of new infections by district into new line for history table.
today="$(date +%Y-%m-%d)"
-curl https://www.berlin.de/lageso/_assets/gesundheit/publikationen/corona/bezirkstabelle.csv \
+curl "${CSV_URL}" \
| awk 'BEGIN { FS=";"; ORS=""; print "'${today}'" }; '\
'!/^Bezirk/ { printf "%4d", $3 }; '\
-'END { printf "\n" }' "${filename}" >> /home/plom/meldetabelle/daily_infections_table.txt
+'END { printf "\n" }' "${filename}" >> "${table_path}"
# Write enhanced table output to directory served by web server.
-./enhance_table.py > /var/www/html/berlin_corona.txt
+#
+# 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/