Commit 838e96f6 authored by Thomas Tsiakalakis's avatar Thomas Tsiakalakis

Update download.sh

parent 527acd08
......@@ -12,22 +12,18 @@ 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')
widgetUrl=$(curl -s https://rap.real.de/endpoints.js | grep 'samlIframe' | sed -re 's/.*"samlIframe":"([^"]+)".*/\1/g' | sed -e 's#\\##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')
loginUrl=$(curl -Ls --cookie ${tmpdir}/cookies.txt --cookie-jar ${tmpdir}/cookies.txt -o /dev/null -w %{url_effective} ${widgetUrl}'?origin=https%3A%2F%2Fwww.real.de%2Fonline-kassenbons%2F')
echo -n '.'
statuscode=$(curl ${loginUrl} -Ls --cookie ${tmpdir}/cookies.txt --cookie-jar ${tmpdir}/cookies.txt -o /dev/null -w "%{http_code}" -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'classicLogin_User='${email} --data-urlencode 'classicLogin_Password='${password})
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
exit 1
fi
echo ' OK'
......@@ -53,14 +49,15 @@ 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
filename="$(date +%Y%m%d%H%M%SZ) - real - ${bonid} - Rechnung.pdf"
if [ -f "${downloadpath}/${filename}" ]; 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}
curl -s --cookie ${tmpdir}/cookies.txt -o "${downloadpath}/${filename}" '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
echo 'DONE'
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