Finance/Quote/Morningstarde.pm: rework logic to use id-map and base-url

This commit is contained in:
Matthias Merz 2020-06-03 22:19:47 +02:00
parent 9b40eaa957
commit f2229bca6d

View File

@ -23,23 +23,13 @@ use POSIX qw(strftime);
my $agent_string = 'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'; my $agent_string = 'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0';
my %urlmap_wkn = ( sub baseurl {
'986855' => 'https://www.morningstar.de/de/funds/snapshot/snapshot.aspx?id=F0GBR04DI1' return 'https://www.morningstar.de/de/funds/snapshot/snapshot.aspx?id=';
); }
my %wknmap = ( my %idmap = (
'de0005326565' => '532656', '986855' => 'F0GBR04DI1',
'de000a0m8hd2' => 'a0m8hd', 'lu0048293285' => 'F0GBR04DI1',
'de000a0x7541' => 'a0x754',
'de000a0x7582' => 'a0x758',
'de000ewg0ld1' => 'ewg0ld',
'fr0010135103' => 'a0dpw0',
'lu0087412390' => '974515',
'lu0323578657' => 'a0m430',
'lu0327386487' => 'dws0pr',
'lu0336084032' => 'a0m9a2',
'lu0438336264' => 'a0ndda',
'lu0454071019' => 'a0ya5q'
); );
sub methods {return ('morningstarde' => \&morningstarde);} sub methods {return ('morningstarde' => \&morningstarde);}
@ -52,12 +42,10 @@ sub labels { return (morningstarde => \@labels); }
sub get_stock_url { sub get_stock_url {
my $stock_wkn = shift; my $stock_wkn = shift;
my $url = $urlmap_wkn{lc($stock_wkn)}; my $id = $idmap{lc($stock_wkn)};
if (!defined($url) || length($url) == 0) { if (defined($id)) {
my $wkn = $wknmap{lc($stock_wkn)}; return baseurl() . $id;
$url = $urlmap_wkn{$wkn}; };
}
return $url;
} }
@ -105,7 +93,6 @@ sub morningstarde
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)) {
print "got datestr: $datestr\r\n";
my $tradedate = $datestr; my $tradedate = $datestr;
$tradedate =~ s/.*\|\s*(\d\d.*) $/$1/g; $tradedate =~ s/.*\|\s*(\d\d.*) $/$1/g;
if (length($tradedate) < 10) { if (length($tradedate) < 10) {