-
Notifications
You must be signed in to change notification settings - Fork 0
/
update
executable file
·39 lines (33 loc) · 926 Bytes
/
update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
set -e
if [[ -f "fallzahlen.csv" ]]
then
FIRST=$(tail -1 fallzahlen.csv | awk -F, '{print $6}')
else
FIRST=$(ls artikel/*.html | tail -1 | tr -cd '0-9')
fi
if [[ -z "$FIRST" ]]
then
FIRST=3064
else
FIRST=$((FIRST+1))
fi
# The RSS feed at least contains the newest article ID
LAST=$(curl -s "https://www.goettingen.de/magazin/view-irss.php?feedid=1" | grep -Po 'artikel=\K[0-9]+' | sort -rn | head -1)
# header
[[ -f fallzahlen.csv ]] || echo "datum,update,gemeinde,faelle,infizierte,quelle" > fallzahlen.csv
# download and analyze new articles
for ID in $(seq $FIRST $LAST)
do
./download $ID
./fallzahlen artikel/$ID.html >> fallzahlen.csv
sleep 1
done
COMMIT=$1
CHANGED=$(git diff-index --name-only HEAD --)
if [[ "$COMMIT" == "commit" && "$CHANGED" == "fallzahlen.csv" ]]
then
DATE=$(tail -1 fallzahlen.csv | awk -F, '{print $1}')
git add fallzahlen.csv
git commit -m "Update $DATE"
fi