Last active
April 19, 2021 06:41
-
-
Save AndiH/8d2233c6a3e4bb546bdeebe0dff005cb to your computer and use it in GitHub Desktop.
Impf Extraction
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
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
Kreis | Erstimpfung | Folgeimpfung | Erstimpfung | Folgeimpfung | Erstimpfung | Folgeimpfung | Summe | |
---|---|---|---|---|---|---|---|---|
Aachen | 93.368 | 34.456 | 13.845 | 39 | 107.213 | 34.495 | 141.708 |
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
#!/usr/bin/env bash | |
URL="https://coronaimpfung.nrw/fileadmin/ci_dateien/pdf/Durchgef%C3%BChrte_Impfungen_je_Kreis.pdf" | |
DATE=$(date +"%Y-%m-%d") | |
curl -o "${DATE}.pdf" ${URL} | |
echo "Written ${DATE}.pdf" |
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
#!/usr/bin/env bash | |
INPUT="$1" | |
OUTPUT="${INPUT%.*}.csv" | |
pdftotext -layout ${INPUT} - | grep -e 'Erstimpfung\|Aachen' | tr -s " " "," | sed 's/,Erstimpfung/Kreis,Erstimpfung/' > ${OUTPUT} |
Und hier wird es noch in ein CSV geschrieben. Die Kopfzeile muss man dann natürlich manuell einbauen, empfiehlt sich aber ja eh, da Feldnamen sich sonst doppeln.
#!/bin/sh
URL="https://coronaimpfung.nrw/fileadmin/ci_dateien/pdf/Durchgef%C3%BChrte_Impfungen_je_Kreis.pdf"
# get file
PDF=impfungen.pdf
curl -so $PDF ${URL}
# extract date
REAL_DATE=`pdftotext -layout $PDF - | egrep -o ".?.?\..?.?\..?.?.?.?" | head -1`
DATE=`pdftotext -layout $PDF - | egrep -o ".?.?\..?.?\..?.?.?.?" | head -1 | tr -s "." "_"`
# write single csv
OUTPUT="${DATE}.csv"
pdftotext -layout $PDF - | grep -e 'Erstimpfung\|Aachen' | tr -s " " "," | sed 's/,Erstimpfung/Kreis,Erstimpfung/' > ${OUTPUT}
# append to CSV
CSV="impfungen.csv"
if ! grep -q $REAL_DATE "$CSV"; then
pdftotext -layout $PDF - | grep -e 'Aachen' | tr -s " " "," | sed 's/Aachen/'${REAL_DATE}'/' >> ${CSV}
fi
Ah, sehr gut. Für diese Datums-Regex war ich zu faul 😬
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Das wäre nun meine Lösung, die auch eine Datei mit dem im PDF angegebenen Datum anlegt.
Schöner wäre natürlich noch, wenn es eine neue Zeile in das CSV einfügt.. Mach ich vielleicht nocht.