Hi everyone
Just want to share my script to generate a HTML-Table which PP can read. It’s mostly for Swiss ETFs since I couldn’t find them anywhere else. I’m not a programmer so be gentle with my programming skills
To help the search-engine here are the ETFs I use:
- SGKB
- Swisscanto
- CSIF (VIAC)
I publish them via a Webserver so I can use the “Table on Website” Option and I let the Scripts run via a Cron-Job, so PP can just poll the data when I open it.
For www.onvista.de
Get the URL:
- Search for the ETF
- Click on Alle Kurse & Handelsplätze
- Select Currency and Timerange
- Open Developer Settings via F12 and Switch to the Network Tab
- Clear the current Log and click on “Download als CSV” on the Website
- Now in the Developer Settings you have the Link directly to the Historic Values
Use this Link in the following Script:
Variables to change are:
- all_url_cash: Array for the URLs
- arr_isin: ISIN of the ETF
- path_html: Destination where the HTML-File will be stored
#!/bin/bash
arr_url_cash=(\
"https://api.onvista.de/api/v1/instruments/FUND/18490292/eod_history?idNotation=206747561&range=Y5&startDate=2016-09-03" \
"https://api.onvista.de/api/v1/instruments/FUND/19908300/eod_history?idNotation=22128766&range=Y5&startDate=2016-09-03" \
"https://api.onvista.de/api/v1/instruments/FUND/17827095/eod_history?idNotation=281108121&range=Y5&startDate=2016-09-03" \
"https://api.onvista.de/api/v1/instruments/FUND/17827091/eod_history?idNotation=206747547&range=Y5&startDate=2016-09-03" \
"https://api.onvista.de/api/v1/instruments/FUND/11473305/eod_history?idNotation=10668488&range=Y5&startDate=2016-09-03" \
"https://api.onvista.de/api/v1/instruments/FUND/17827093/eod_history?idNotation=281108113&range=Y5&startDate=2016-09-03" \
)
arr_isin=(\
"CH0033782431" \
"CH0037606552" \
"CH0030849613" \
"CH0030849654" \
"CH0017844686" \
"CH0030849712" \
)
path_html="/home/pi/docker/ha/www/"
for (( y=0;y<${#arr_url_cash[@]};y++ ))
do
rm "${path_html}${arr_isin[$y]}.html"
historic_full=$(wget -O - "${arr_url_cash[$y]}")
IFS='['
xcounter=0
for x in $historic_full
do
IFS=','
for z in $x
do
case $xcounter in
1)
arr_date+=("$z")
;;
3)
arr_price+=("$z")
;;
esac
done
((xcounter++))
done
printf "<table>\n<tr><th>Date.*</th><th>Schluss.*</th></tr>" >> "${path_html}${arr_isin[$y]}.html"
for (( i=0;i<${#arr_date[@]}-1;i++ ))
do
printf "\n<tr><td>$(date -d @${arr_date[$i]//]} +"%Y-%m-%d")</td><td>${arr_price[$i]//]}</td></tr>" >> "${path_html}${arr_isin[$y]}.html"
done
printf "\n</table>" >> "${path_html}${arr_isin[$y]}.html"
unset IFS
unset arr_date
unset arr_price
done
Get the URL:
- Search for the ETF
- Right Click on Download historische Werte to Copy URL
Use this Link in the following Script:
Variables to change are:
- all_url_cash: Array for the URLs
- arr_isin: ISIN of the ETF
- path_html: Destination where the HTML-File will be stored
#!/bin/bash
arr_url_cash=("https://fonds.cash.ch/funds/excelData/40239" "https://fonds.cash.ch/funds/excelData/87121")
arr_isin=("CH0238046459" "CH0373465365")
path_html="/home/pi/docker/ha/www/"
skip_lines=2
for (( y=0;y<${#arr_url_cash[@]};y++ ))
do
rm "${arr_isin[$y]}.csv"
rm "${path_html}${arr_isin[$y]}.html"
wget -O "${arr_isin[$y]}.csv" "${arr_url_cash[$y]}"
print_header=true
x=0
echo "<table>" >> "${path_html}${arr_isin[$y]}.html";
while read INPUT ; do
if (($x >= $skip_lines)); then
if $print_header;then
echo "<tr><th>$INPUT" | sed -e 's/Date/Date.*/g' -e 's/;Chart[[:space:]]Price;/;Schluss.*;/g' -e 's/Price//g' -e 's/;/<\/th><th>/g' -e 's/$/<\/th><\/tr>/' >> "${path_html}${arr_isin[$y]}.html"
print_header=false
else
echo "<tr><td>${INPUT//;/</td><td>}</td></tr>" >> "${path_html}${arr_isin[$y]}.html" ;
fi
fi
((x++))
done < "${arr_isin[$y]}.csv" ;
echo "</table>" >> "${path_html}${arr_isin[$y]}.html"
rm "${arr_isin[$y]}.csv"
done
WARNING: This one is really ugly but so far it works
Get the URL:
- Search for the Product, the Website does not always display it the same way for everything. For this to work it has to look like this: CREDIT SUISSE INDEX FUND (CH) - CSIF (CH) EQUITY SWITZERLAND SMALL & MID CAP ZB FONDS Fonds | aktueller Kurs | 11086914 | finanzen.ch
- It has to have the Nettoinventarwert, Vortag and Datum since the Script searches for this Words
- Since there are not always Historic values this script appends the current data to the HTML file, you only have data from the first time on when you’ve run the script
Use this Link in the following Script:
Variables to change are:
- all_url_cash: Array for the URLs
- arr_isin: ISIN of the ETF
- path_html: Destination where the HTML-File will be stored
#!/bin/bash
arr_url_cash=(\
"https://www.finanzen.ch/fonds/credit-suisse-index-fund-ch-csif-ch-equity-switzerland-small-mid-zb-ch0110869143" \
"https://www.finanzen.ch/fonds/csif-ch-i-equity-japan-blue-pension-fund-zb-ch0357515474" \
)
arr_isin=(\
"CH0110869143" \
"CH0357515474" \
)
path_html="/home/pi/docker/ha/www/"
for (( y=0;y<${#arr_url_cash[@]};y++ ))
do
if test -f "${path_html}${arr_isin[$y]}.html"; then
sed -i '$d' "${path_html}${arr_isin[$y]}.html"
else
printf "<table>\n<tr><th>Date.*</th><th>Price</th></tr>\n" >> "${path_html}${arr_isin[$y]}.html"
fi
historic_full=$(wget -O - "${arr_url_cash[$y]}")
IFS='/'
printnextline=false
for x in $historic_full
do
if $printnextline;then
case $nextvariable in
closeprice)
closeprice=$( printf "${x}" | sed 's/[^0-9.]*//g' | sed -z 's/\n//g')
;;
closepricedate)
closepricedate=$( printf "${x}" | sed 's/[^0-9.]*//g' | sed -z 's/\n//g')
;;
currentprice)
currentprice=$( printf "${x}" | sed 's/[^0-9.]*//g' | sed '$!d' )
;;
currentpricedate)
currentpricedate=$( printf "${x}" | sed 's/[^0-9.]*//g' | sed -z 's/\n//g')
;;
esac
printnextline=false
fi
case $x in
*Vortag*)
nextvariable="closeprice"
printnextline=true
;;
*Datum*)
nextvariable="closepricedate"
printnextline=true
;;
*Nettoinventarwert*)
nextvariable="currentprice"
printnextline=true
;;
*Berichtsstand*)
nextvariable="currentpricedate"
printnextline=true
;;
esac
done
sed -i "/${closepricedate}/d" "${path_html}${arr_isin[$y]}.html"
sed -i "/${currentpricedate}/d" "${path_html}${arr_isin[$y]}.html"
printf "<tr><td>${closepricedate}</td><td>${closeprice}</td></tr>\n" >> "${path_html}${arr_isin[$y]}.html"
printf "<tr><td>${currentpricedate}</td><td>${currentprice}</td></tr>\n" >> "${path_html}${arr_isin[$y]}.html"
printf "</table>" >> "${path_html}${arr_isin[$y]}.html"
unset IFS
done