Last active
February 19, 2023 12:13
-
-
Save dedeibel/ed6a5956d4e309e52fe1b39196195c58 to your computer and use it in GitHub Desktop.
Kreditkarten Abrechnungen PDF von LBB Berlin Amazon Kreditkarte zu CSV konvertieren parse parsen BEST EFFORT
This file contains hidden or 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/perl -n | |
# | |
# Achtung: Das Skript ist ein fieser Hack, welcher vermutlich nicht in allen | |
# Faellen funktioniert. Fuer mich hat es fuer erste Experimente | |
# ausreichend gut funktioniert. | |
# | |
# Einzelne Ausgabe von "pdf2txt" einer einer einzelnen PDF Datei | |
# als Parameter oder via Pipe uebergeben. | |
# | |
# Ausgabe der Buchungen erfolgt als CSV auf stdout. Mittels gnucash importierbar. | |
# | |
# "pdf2txt" findet man z.B. im debian Paket "python-pdfminer" | |
# | |
# | |
use Text::CSV qw(csv); | |
BEGIN { | |
my @entries; | |
} | |
s/[\d.]+,\d\d [+-](Visa Karte|jahreskartenpreis|gutschein kartenpreis).*?(?=\d\d\.\d\d\.\d\d\d\d)//gsi; | |
s/(USD|GBP)\d+,\d\d [+-][\d.]+,\d{5}//gs; | |
while (m/(\d\d\.\d\d\.\d\d\d\d)(.{1,250}?)(\d\d\.\d\d\.\d\d\d\d)([\d.]+,\d\d) ?([+-])/gs) { | |
my $sign = ''; | |
$sign = '-' unless $5 eq '+'; | |
my $value = $sign . $4; | |
my $entry = [$1, $2, $3, $value]; | |
push(@entries, $entry); | |
} | |
while (m/(\d\d\.\d\d\.\d\d\d\d)(.{1,55}?)(\d\d\.\d\d\.\d\d\d\d).{1,50}?AUSLANDSEINSATZENTGELT((\d|\.)+,\d\d) ?([+-])/gs) { | |
my $sign = ''; | |
$sign = '-' unless $5 eq '+'; | |
my $value = $sign . $4; | |
my $entry = [$1, $2 . ' AUSLANDSENDGELT', $3, $value]; | |
push(@entries, $entry); | |
} | |
END { | |
csv(in => \@entries); | |
} |
This file contains hidden or 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 | |
# PDFs im Batch aendern | |
# for i in *pdf ; do echo "$i" ; lbb-pdf-to-csv "$i" ; done | |
set -e | |
FILE=$1 | |
FILE_OUT=`dirname ${FILE}`/`basename "${FILE}" .pdf`.csv | |
pdf2txt "${FILE}" \ | |
| lbb-extract-transactions-from-text.pl \ | |
> "${FILE_OUT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Very helpful!