home · contact · privacy
Create table dynamically so it's not overwritten by git updates.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 30 Jun 2020 21:54:58 +0000 (23:54 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 30 Jun 2020 21:54:58 +0000 (23:54 +0200)
daily_infections_table.txt [deleted file]
update.sh

diff --git a/daily_infections_table.txt b/daily_infections_table.txt
deleted file mode 100644 (file)
index 578b849..0000000
+++ /dev/null
@@ -1 +0,0 @@
-            CW  FK  Li  MH  Mi  Ne  Pa  Re  Sp  SZ  TS  TK sum
index 1a84c8ba9fa70208f7c7693d151b52c03be487ca..f1b74677156a796631ca10086f2ec2ff87378ca5 100755 (executable)
--- a/update.sh
+++ b/update.sh
@@ -1,11 +1,21 @@
 #!/bin/sh
 #!/bin/sh
+set -e
+
+CSV_URL=https://www.berlin.de/lageso/_assets/gesundheit/publikationen/corona/bezirkstabelle.csv 
+table_path=/home/plom/berlin-corona-table/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)"
 
 # 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 }; '\
 | awk 'BEGIN { FS=";"; ORS=""; print "'${today}'" }; '\
 '!/^Bezirk/ { printf "%4d", $3 }; '\
-'END { printf "\n" }' "${filename}" >> /home/plom/berlin-corona-table/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
 
 # Write enhanced table output to directory served by web server.
 ./enhance_table.py > /var/www/html/berlin_corona.txt