From cea3bbc91705bf4ce0c343402c357454fe9dab7b Mon Sep 17 00:00:00 2001 From: Matthias Merz Date: Tue, 7 Jun 2016 22:08:28 +0200 Subject: [PATCH] DKB: whitelist fonds-URLs --- Finance/Quote/DKB.pm | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/Finance/Quote/DKB.pm b/Finance/Quote/DKB.pm index 27c67a2..e7c22d3 100644 --- a/Finance/Quote/DKB.pm +++ b/Finance/Quote/DKB.pm @@ -20,13 +20,46 @@ package Finance::Quote::DKB; use strict; use HTML::TreeBuilder::XPath; -my $BASE_URL = "https://dkb.mdgms.com/MIS/?id_instrument=19035880&id=0107980&pid=DKB_fnd_profile&id_notation=23679474"; +my %urlmap_wkn = ( + 'a0m9a2' => 'https://dkb.mdgms.com/MIS/?id_instrument=19035880&id=0107980&pid=DKB_fnd_profile&id_notation=23679474', + 'a0m430' => 'https://dkb.mdgms.com/MIS/?id_instrument=18085585&id=0107980&pid=DKB_fnd_profile&id_notation=20644387', + 'a0ya5q' => 'https://dkb.mdgms.com/MIS/?id_instrument=26097198&id=0107980&pid=DKB_fnd_profile&id_notation=32652184', + '974515' => 'https://dkb.mdgms.com/MIS/?id_instrument=102918&id=0107980&pid=DKB_fnd_profile&id_notation=3228063', + 'a0dpw0' => 'https://dkb.mdgms.com/MIS/?id_instrument=11659733&id=0107980&pid=DKB_fnd_profile&id_notation=11014630', + 'a0x754' => 'https://dkb.mdgms.com/MIS/?id_instrument=22407622&id=0107980&pid=DKB_fnd_profile&id_notation=26567264', + 'a0m8hd' => 'https://dkb.mdgms.com/MIS/?id_instrument=19179789&id=0107980&pid=DKB_fnd_profile&id_notation=21240603', + 'dws0pr' => 'https://dkb.mdgms.com/MIS/?id_instrument=18286450&id=0107980&pid=DKB_fnd_profile&id_notation=22946309' +); + +my %wknmap = ( + 'lu0336084032' => 'a0m9a2', + 'lu0323578657' => 'a0m430', + 'lu0454071019' => 'a0ya5q', + 'lu0087412390' => '974515', + 'fr0010135103' => 'a0dpw0', + 'de000a0x7541' => 'a0x754', + 'de000a0m8hd2' => 'a0m8hd', + 'lu0327386487' => 'dws0pr' +); sub methods {return ('dkb' => \&dkb, 'europe' => \&dkb);} sub labels { return (dkb=>[qw/name date price currency/]); } + +sub get_stock_url { + my $stock_wkn = shift; + + my $url = $urlmap_wkn{lc($stock_wkn)}; + if (!defined($url) || length($url) == 0) { + my $wkn = $wknmap{lc($stock_wkn)}; + $url = $urlmap_wkn{$wkn}; + } + return $url; +} + + sub dkb { my $quoter = shift; # The Finance::Quote object. @@ -36,7 +69,12 @@ sub dkb my %info; foreach my $stock (@stocks) { - my $response = $ua->get($BASE_URL . "&search_value=" . $stock); + my $get_url = get_stock_url($stock); + if (!defined($get_url) || length($get_url) == 0) { + $info{$stock,"errormsg"} = "undefined DKB-UR"; + next; + } + my $response = $ua->get($get_url . "&search_value=" . $stock); #print $response->content, "\n"; $info{$stock,"success"} = 0; if (!$response -> is_success()) { @@ -56,7 +94,6 @@ sub dkb my @splitvals = ( $pricestr =~ /((\d|,|\.)*)\s*/g); if (@splitvals) { $info{$stock,'price'} = $splitvals[0]; - $info{$stock,'last'} = $splitvals[0]; if ($pricestr =~ /EUR/) { $info{$stock,'currency'} = 'EUR'; }