Commit a8d86722 authored by Thomas Tsiakalakis's avatar Thomas Tsiakalakis

initial commit

parent 465b6217
bons/*
\ No newline at end of file
# real-bons
this is a script that can log in to real.de and fetch all Receipt PDFs
# requirements
* PayBack Card with enabled Online Receipt
* `jq` installed
# usage
* set email address and password variables
* run
# example
```
$ ./download.sh
Loggin in... OK
Fetching Cards... OK
found cards:
0123456789012345
fetching receipt list for card
0123456789012345... OK
DONE
fetching 544 receipts...
0123456789012345678901234.pdf SKIPPING
0123456789012345678901235.pdf DOWNLOADING OK
0123456789012345678901236.pdf DOWNLOADING OK
DONE
```
\ No newline at end of file
#!/bin/bash
email=''
password=''
downloadpath='./bons'
limityear='2019' # 0 = no limit
limitmonth='0' # 0 = no limit
##########
set -e
tmpdir=$(mktemp -d)
echo -n 'Loggin in.'
sessionDataKey=$(curl -Ls --cookie-jar ${tmpdir}/cookies.txt 'https://rap.real.de/saml?origin=https%3A%2F%2Fwww.real.de%2Fnc%2Fonline-kassenbons%2Fmeine-einkaeufe%2F' | egrep 'input.*sessionDataKey' | sed -re 's/.*value='\''([^'\'']+)'\''.*/\1/g')
echo -n '.'
statuscode=$(curl -s --cookie ${tmpdir}/cookies.txt -w "%{http_code}" --cookie-jar ${tmpdir}/cookies.txt -o ${tmpdir}/samldata.html 'https://login.real-ident.de/samlsso' -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'tocommonauth=true' --data-urlencode 'username='${email} --data-urlencode 'password='${password} --data-urlencode 'sessionDataKey='${sessionDataKey})
if [[ "${statuscode}" -ne "200" ]]; then
echo ' FAILED'
exit 1
fi
SAMLResponse=$(egrep 'input.*SAMLResponse' ${tmpdir}/samldata.html | sed -re 's/.*value='\''([^'\'']+)'\''.*/\1/g')
RelayState=$(egrep 'input.*RelayState' ${tmpdir}/samldata.html | sed -re 's/.*value='\''([^'\'']+)'\''.*/\1/g')
echo -n '.'
statuscode=$(curl -s --cookie ${tmpdir}/cookies.txt -w "%{http_code}" --cookie-jar ${tmpdir}/cookies.txt -o /dev/null 'https://rap.real.de/saml/acs' -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'RelayState='${RelayState} --data-urlencode 'SAMLResponse='${SAMLResponse})
if [[ "${statuscode}" -ne "200" ]]; then
echo ' FAILED'
exit 2
fi
echo ' OK'
echo -n 'Fetching Cards...'
curl -s --cookie ${tmpdir}/cookies.txt -XPOST 'https://www.real.de/nc/online-kassenbons/meine-einkaeufe/?type=201806221054&no_cache=1&filter=1' | jq -r '.paybackCards | keys[]' > ${tmpdir}/cards.txt
echo ' OK'
echo 'found cards:'
while read card; do
echo ' '$card
done < ${tmpdir}/cards.txt
echo
echo 'fetching receipt list for card '
while read card; do
echo -n ' '$card'...'
curl -s --cookie ${tmpdir}/cookies.txt 'https://www.real.de/nc/online-kassenbons/meine-einkaeufe/?type=201806221054&no_cache=1&filter=1' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data-urlencode 'paybackFilter='${card} --data-urlencode 'monthFilter='${limitmonth} --data-urlencode 'yearFilter='${limityear} | jq -r '.bons.items[].bonId' >> ${tmpdir}/bonids.txt
echo ' OK'
done < ${tmpdir}/cards.txt
echo 'DONE'
echo 'fetching '$(wc -l ${tmpdir}/bonids.txt | awk '{ print $1 }')' receipts...'
mkdir -p ${downloadpath}
while read bonid; do
echo -n ' '${bonid}.pdf
if [ -f ${downloadpath}/${bonid}.pdf ]; then
echo ' SKIPPING'
else
echo -n ' DOWNLOADING'
curl -s --cookie ${tmpdir}/cookies.txt -o ${downloadpath}/${bonid}.pdf 'https://www.real.de/online-kassenbons/meine-einkaeufe/?type=201807041728&no_cache=1&bonid='${bonid}
echo ' OK'
fi
done < ${tmpdir}/bonids.txt
rm -rf ${tmpdir}
echo 'DONE'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment