Finance/Quote/Morningstarde.pm: parse dynamic table-row for currency

This commit is contained in:
Matthias Merz 2020-07-10 23:18:07 +02:00
parent a56620543e
commit 960ad436f6

View File

@ -84,7 +84,9 @@ sub morningstarde
$info{$stock,'name'} = $namestr; $info{$stock,'name'} = $namestr;
}; };
my $pricestr = $parser->findnodes('//div[@id="overviewQuickstatsDiv"]//tr[2]/td[3]'); my $row = 2;
while (!defined($info{$stock,'currency'}) && $row <=10) {
my $pricestr = $parser->findnodes('//div[@id="overviewQuickstatsDiv"]//tr[' . $row . ']/td[3]');
if (defined($pricestr)) { if (defined($pricestr)) {
my @splitvals = ( $pricestr =~ /(\w+).([0-9,.]+)/g); my @splitvals = ( $pricestr =~ /(\w+).([0-9,.]+)/g);
if (@splitvals) { if (@splitvals) {
@ -94,7 +96,14 @@ sub morningstarde
$converted_price =~ s/,/./g; $converted_price =~ s/,/./g;
$info{$stock,'nav'} = $converted_price; $info{$stock,'nav'} = $converted_price;
} }
# if it does not look like a currency, try next row
if ($info{$stock,'currency'} !~ /\w{2,3}/) {
undef $info{$stock,'currency'};
}
$row++;
}; };
}
my $datestr = $parser->findnodes('//div[@id="overviewQuickstatsDiv"]//tr[2]/td[1]//span'); my $datestr = $parser->findnodes('//div[@id="overviewQuickstatsDiv"]//tr[2]/td[1]//span');
if (defined($datestr)) { if (defined($datestr)) {