Skip to content

Instantly share code, notes, and snippets.

@AndiH
Last active April 19, 2021 06:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndiH/8d2233c6a3e4bb546bdeebe0dff005cb to your computer and use it in GitHub Desktop.
Save AndiH/8d2233c6a3e4bb546bdeebe0dff005cb to your computer and use it in GitHub Desktop.
Impf Extraction
Kreis Erstimpfung Folgeimpfung Erstimpfung Folgeimpfung Erstimpfung Folgeimpfung Summe
Aachen 93.368 34.456 13.845 39 107.213 34.495 141.708
#!/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"
#!/usr/bin/env bash
INPUT="$1"
OUTPUT="${INPUT%.*}.csv"
pdftotext -layout ${INPUT} - | grep -e 'Erstimpfung\|Aachen' | tr -s " " "," | sed 's/,Erstimpfung/Kreis,Erstimpfung/' > ${OUTPUT}
@mrtopf
Copy link

mrtopf commented Apr 18, 2021

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.

#!/bin/sh

URL="https://coronaimpfung.nrw/fileadmin/ci_dateien/pdf/Durchgef%C3%BChrte_Impfungen_je_Kreis.pdf"

# temporary import file
PDF=impfungen.pdf

# extract date
curl -so $PDF ${URL}
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}

@mrtopf
Copy link

mrtopf commented Apr 18, 2021

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

@AndiH
Copy link
Author

AndiH commented Apr 19, 2021

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