Created
January 26, 2021 14:59
-
-
Save Fabian42/4c367a86b405bb5f3c5f4e164cd2abc3 to your computer and use it in GitHub Desktop.
Corona sheet filling script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## NOTE: I'm publishing this here on Pastebin, but that doesn't mean that I would recommend running it. Some aliases only exist on my computer, so the script would without changes not work on other computers. Some of the parsing is also pretty hacked together and might break at any point, especially with changes to the sources. Quite a few assumptions are made, only one part even has any error handling at all and for example getting the JSON out of a website to parse it properly is harder and probably not better than just using grep and my own limited parser. | |
# abort if not executed with aliases etc. working | |
if [[ $- != *i* ]]; then return; fi | |
insert_full(){ | |
xdotool key Down sleep 1 key Shift+KP_Insert sleep 60 key Alt+Down sleep 3 | |
} | |
insert_one(){ | |
xdotool key Ctrl+Down sleep 1 key Down sleep 1 key Shift+KP_Insert sleep 60 key Alt+Down sleep 3 | |
} | |
altkreis_assumption(){ | |
xdotool key Ctrl+Down sleep 1 key Ctrl+c sleep 1 key Down sleep 1 key Shift+KP_Insert sleep 60 key Alt+Down sleep 3 | |
} | |
insert_worldometers(){ | |
# $1 is the number of preceding 0s | |
# $2 is the series name to be searched | |
out=$(ech "$page" | grep -i -m 1 --after-context=5 "name: '$2'" | grep -i data | sed -E "s/ *data\\: \\[//" | sed -E "s/\\] *\\} *\\]? *\\,? *\\{? *//" | sed -E "s/null/0/g" | sed "s/\\-[0-9]+/0/g" | sed -E "s/\\,/\\n/g") | |
for i in $(seq 1 "$1"); do | |
out="0\n$out" | |
done | |
ech "$out" | xclip -selection clipboard | |
insert_full | |
} | |
### START | |
# open sheet | |
(firefox "docs.google.com/spreadsheets/d/1uDTghO_ZYBs5nfs2kDc0Ms6e9bbx7clx_QgkWii7OMY" &> /dev/null & disown) | |
sleep 60 | |
# vaccination Germany | |
#export IFS=$'\n' | |
ech "0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n$(wget -q -O - "impfdashboard.de/static/data/germany_vaccinations_timeseries_v2.tsv" | tail -n +2 | while read line; do echo $line | sed "s/([0-9\\-]+ +){6}([0-9\\-]+).*/\\2/"; done)" | xclip -selection clipboard | |
insert_full | |
# vaccination Austria | |
# `echo "$()"` adds a trailing newline so that `while read` doesn't skip the last line | |
ech "0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n8360\\n8360\\n$(echo "$(wget -q -O - "info.gesundheitsministerium.gv.at/data/national.csv")" | tail -n +13 | while read line; do echo "$line" | sed "s/[0-9\-]+\\;([0-9]*)\\;.*/\\1/"; done)" | xclip -selection clipboard | |
insert_full | |
# Germany | |
page=$(wget -q -O - "worldometers.info/coronavirus/country/germany") | |
insert_worldometers 0 "Currently infected" | |
insert_worldometers 0 "New cases" | |
insert_worldometers 68 "Daily deaths" | |
# Saxony | |
page="$(wget -q -O - "services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_COVID19_Landkreise_Table_Demo_18b5f806160a4aa686ca65819fbe4462/FeatureServer/0/query?where=GEN%3D%27Nordsachsen%27+or+GEN%3D%27Sachsen%27&outFields=cases%2Cdeaths&orderByFields=GEN&f=pgeojson")" | |
total_saxony=$(echo "$page" | grep "cases" | tail -n 1 | grep -o -E "[0-9]+") | |
qalc -t "$total_saxony-$(cat /home/fabian/misc/corona_storage | head -n 1)" | sed "s/−[0-9]+/0/" | sed "s/\\\"//g" | xclip -selection clipboard | |
insert_one | |
dead_saxony_now=$(echo "$page" | grep "deaths" | tail -n 1 | grep -o -E "[0-9]+") | |
qalc -t "$dead_saxony_now-$(cat /home/fabian/misc/corona_storage | head -n 2 | tail -n 1)" | sed "s/−[0-9]+/0/" | sed "s/\\\"//g" | xclip -selection clipboard | |
insert_one | |
# North Saxony | |
total_north_saxony=$(echo "$page" | grep "cases" | head -n 1 | grep -o -E "[0-9]+") | |
qalc -t "$total_north_saxony-$(cat /home/fabian/misc/corona_storage | head -n 3 | tail -n 1)" | sed "s/−[0-9]+/0/" | sed "s/\\\"//g" | xclip -selection clipboard | |
insert_one | |
# world | |
page=$(wget -q -O - "worldometers.info/coronavirus") | |
insert_worldometers 0 "Currently infected" | |
insert_worldometers 0 "Daily cases" # because consistency | |
insert_worldometers 0 "Daily deaths" | |
# Lower Saxony | |
page=$(wget -q -O - "www.apps.nlga.niedersachsen.de/corona/download.php?csv_tag") | |
ech "$page" | grep "\\." | while read line; do | |
ech "$line" | sed "s/[0-9]+\\.[0-9]+\\.[0-9]+\;//" | sed "s/\\-[0-9]+/0/g" | tr ";" "\n" | head -n 1 # "-" is speculative, it never happened here before | |
done | xclip -selection clipboard | |
insert_full | |
ech "$page" | grep "\." | while read line; do | |
echo "$line" | sed "s/[0-9]+\\.[0-9]+\\.[0-9]+\\;[0-9]+\\;[0-9\.]+\\;//" | sed "s/\\-[0-9]+/0/g" # speculative "-" | |
done | xclip -selection clipboard | |
insert_full | |
# Hannover cases (and preparation for the rest of Hannover and Lehrte) | |
# This breaks if 20 or more articles were published today after the Corona update. I could fix that, but it's extremely unlikely. Changes to the website are much more likely. | |
links=$(wget --no-check-certificate -q -O - "www.altkreisblitz.de/region-hannover" | grep -E "<div class\\=\\\"news\\-list\\-item\\-title\\\"><h2><a href\\=\\\"https\\:\\/\\/www\\.altkreisblitz\\.de\\/aktuelles\\/datum\\/$(date "+%Y\\/%m\\/%d")" | grep -o -E "https[^\\\"]+") | |
#links=$(wget --no-check-certificate -q -O - "www.altkreisblitz.de/region-hannover" | grep -E "<div class\\=\\\"news\\-list\\-item\\-title\\\"><h2><a href\\=\\\"https\\:\\/\\/www\\.altkreisblitz\\.de\\/aktuelles\\/datum\\/2021\\/01\\/25" | grep -o -E "https[^\\\"]+") | |
found=0 | |
for link in $links; do # $links not quoted, because that breaks splitting on newlines for some reason | |
page=$(wget -q -O - "$link") | |
cases_han=$(ech "$page" | grep --after-context=1 -e "Aktuell Infizierte" -e "Aktuell registrierte Infizierte" | grep -o -E "[0-9]+\\.[0-9]+\\.\\: [0-9]+" | head -n 1 | sed "s/[0-9]+\\.[0-9]+\\.\\: //g") | |
dead_han_now=$(ech "$page" | grep -o -E "[0-9]+ Menschen sind infolge einer nachgewiesenen oder mutmaßlichen Corona\\-Infektion in der Region verstorben" | grep -o -E "[0-9]+") | |
cases_lehrte=$(ech "$page" | grep -o -E "Lehrte<\\/p> *<\\/td> *<td> *<p class\\=\\\"bodytext\\\"> *[0-9]+" | grep -o -E "[0-9]+") | |
total_lehrte=$(ech "$page" | grep -o -E "Lehrte<\\/p> *<\\/td> *<td> *<p class\\=\\\"bodytext\\\"> *[0-9]+ *<\\/p> *<\\/td> *<td> *<p class\\=\\\"bodytext\\\"> *[0-9]+" | grep -o -E "[0-9]+" | tail -n 1) | |
if [[ "$cases_han" != "" ]] && [[ "$dead_han_now" != "" ]] && [[ "$cases_lehrte" != "" ]] && [[ "$total_lehrte" != "" ]]; then | |
found=1 | |
dead_han=$(qalc -t "$dead_han_now-$(cat /home/fabian/misc/corona_storage | head -n 4 | tail -n 1)" | sed "s/−[0-9]+/0/" | sed "s/\"//g") | |
new_lehrte=$(qalc -t "$total_lehrte-$(cat /home/fabian/misc/corona_storage | tail -n 1)" | sed "s/−[0-9]+/0/" | sed "s/\\\"//g") | |
ech "$cases_han" | xclip -selection clipboard | |
insert_one | |
break | |
fi | |
done | |
if [[ $found == 0 ]]; then | |
echo "Couldn't find/parse article, skipping. Links checked:\n$links" | |
dead_han_now=$(cat /home/fabian/misc/corona_storage | head -n 4 | tail -n 1) | |
total_lehrte=$(cat /home/fabian/misc/corona_storage | tail -n 1) | |
altkreis_assumption | |
fi | |
ech "$total_saxony\n$dead_saxony_now\n$total_north_saxony\n$dead_han_now\n$total_lehrte" > /home/fabian/misc/corona_storage | |
# Hannover new | |
ech "0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\n$(wget -q -O - "www.apps.nlga.niedersachsen.de/corona/download.php?csv_tag_region" | grep han | while read line; do ech "$line" | sed "s/[0-9]+\\.[0-9]+\\.[0-9]+\\;[0-9]+\\;[0-9]+\\;[^\\;]+\\;//" | tr ";" "\n" | head -n 1 | sed "s/\\-[0-9]+/0/g"; done)" | xclip -selection clipboard | |
insert_full | |
# Hannover dead, Lehrte cases, Lehrte new | |
if [[ $found == 1 ]]; then | |
ech "$dead_han" | xclip -selection clipboard | |
insert_one | |
ech "$cases_lehrte" | xclip -selection clipboard | |
insert_one | |
ech "$new_lehrte" | xclip -selection clipboard | |
insert_one | |
else | |
ech "0" | xclip -selection clipboard | |
insert_one | |
altkreis_assumption | |
ech "0" | xclip -selection clipboard | |
insert_one | |
fi | |
# Lehrte dead, assumed 0 by default | |
ech "0" | xclip -selection clipboard | |
insert_one | |
# Austria | |
page=$(wget -q -O - "worldometers.info/coronavirus/country/austria") | |
insert_worldometers 81 "Currently infected" | |
insert_worldometers 81 "New cases" | |
insert_worldometers 81 "Daily deaths" | |
# prepare manual checks | |
# return to first manually filled sheet (by looping back through last) | |
xdotool key Alt+Up sleep 3 key Alt+Up sleep 3 key Alt+Up sleep 3 key Alt+Up sleep 3 | |
# open pages for manual checks | |
weekday=$(qalc -t "weekday(today)" | sed "s/\\\"//g") | |
if [[ $found == 0 ]] && [[ $weekday -lt 6 ]]; then | |
(firefox "www.altkreisblitz.de/region-hannover" &> /dev/null & disown) | |
sleep 1 | |
fi | |
(firefox "www.altkreisblitz.de/lehrte" &> /dev/null & disown) | |
notify-send -t 10000 "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment