| 1 | # Finance::Quote Perl module to retrieve quotes from Finanzpartner.de | ||||||||||||||||||||||||||||
| 2 | # vi: set ts=2 sw=2 noai expandtab ic showmode showmatch: | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # Copyright (C) 2007 Jan Willamowius <jan@willamowius.de> | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 8 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 17 | # along with this program; if not, write to the Free Software | ||||||||||||||||||||||||||||
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | package Finance::Quote::Finanzpartner; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | use constant DEBUG => $ENV{DEBUG}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use if DEBUG, 'Smart::Comments'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | use Web::Scraper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 5 | our $VERSION = '1.72_01'; # TRIAL VERSION | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | my $FINANZPARTNER_URL = "https://www.finanzpartner.de/fi/"; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | our $DISPLAY = 'Finanzpartner, DE'; | |||||||||||||||||||||||||||
| 35 | 5 | our @LABELS = qw/name date price last method/; | |||||||||||||||||||||||||||
| 36 | 5 | our $METHODHASH = {subroutine => \&finanzpartner, | |||||||||||||||||||||||||||
| 37 | display => $DISPLAY, | ||||||||||||||||||||||||||||
| 38 | labels => \@LABELS}; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 10 | ▶ | sub methodinfo { | ||||||||||||||||||||||||||
|
Subroutine
methodinfo: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | return ( | ||||||||||||||||||||||||||||
| 42 | 10 | finanzpartner => $METHODHASH, | |||||||||||||||||||||||||||
| 43 | germany => $METHODHASH, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 5 | ▶ | sub labels { | ||||||||||||||||||||||||||
|
Subroutine
labels: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 5 | my %m = methodinfo(); return map {$_ => [@{$m{$_}{labels}}] } keys %m; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 5 | ▶ | sub methods { | ||||||||||||||||||||||||||
|
Subroutine
methods: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 5 | my %m = methodinfo(); return map {$_ => $m{$_}{subroutine} } keys %m; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub finanzpartner | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
finanzpartner: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 0 | my $quoter = shift; # The Finance::Quote object. | |||||||||||||||||||||||||||
| 58 | 0 | my @stocks = @_; | |||||||||||||||||||||||||||
| 59 | 0 | my $ua = $quoter->user_agent(); | |||||||||||||||||||||||||||
| 60 | 0 | my %info; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | foreach my $stock (@stocks) { | |||||||||||||||||||||||||||
| 63 | 0 | eval { | |||||||||||||||||||||||||||
| 64 | 0 | my @headers = ( | |||||||||||||||||||||||||||
| 65 | "authority" => "www.finanzpartner.de", | ||||||||||||||||||||||||||||
| 66 | "sec-ch-ua" => '"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"', | ||||||||||||||||||||||||||||
| 67 | "sec-ch-ua-mobile" => "?0", | ||||||||||||||||||||||||||||
| 68 | "upgrade-insecure-requests" => "1", | ||||||||||||||||||||||||||||
| 69 | "user-agent" => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', | ||||||||||||||||||||||||||||
| 70 | "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | ||||||||||||||||||||||||||||
| 71 | "accept-language" => "en-US,en;q=0.9", | ||||||||||||||||||||||||||||
| 72 | "sec-ch-ua" => "\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"", | ||||||||||||||||||||||||||||
| 73 | "sec-fetch-dest" => "document", | ||||||||||||||||||||||||||||
| 74 | "sec-fetch-mode" => "navigate", | ||||||||||||||||||||||||||||
| 75 | "sec-fetch-site" => "none", | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my $url = $FINANZPARTNER_URL . $stock . '/'; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | ### url : $url | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my $reply = $ua->get($url, @headers); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $processor = scraper { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 85 | 0 | process 'span.kurs-m.pull-left', 'price[]' => 'TEXT'; | |||||||||||||||||||||||||||
| 86 | 0 | process 'span.kurs.pull-left', 'price_alternative[]' => 'TEXT'; | |||||||||||||||||||||||||||
| 87 | 0 | process 'h1 > small', 'isin[]' => 'TEXT'; | |||||||||||||||||||||||||||
| 88 | 0 | process 'div.col-md-2', 'date[]' => 'TEXT'; | |||||||||||||||||||||||||||
| 89 | 0 | process 'h1 > span', 'name[]' => 'TEXT'; | |||||||||||||||||||||||||||
| 90 | 0 | }; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $data = $processor->scrape(decode_utf8 $reply->content); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # If price does not exists, then price_alternative should exist. In that case, put price_alternative into price. | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if(exists $data->{price_alternative}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $data->{price} = $data->{price_alternative}; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | ### data: $data | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | die "Unexpected price format" unless exists $data->{price} and $data->{price}->[0] =~ /^([0-9.]+) ([A-Z]+)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $data->{"price"} and $data->{"price"}[0] =~ /^([0-9.]+) ([A-Z]+)$/
MC/DC0%0/2
exists $data->{"price"} and $data->{"price"}[0] =~ /^([0-9.]+) ([A-Z]+)$/
exists $data->{"price"}
$data->{"price"}[0] =~ /^([0-9.]+) ([A-Z]+)$/
Truth table0%0/3
A and B
A= exists $data->{"price"}B= $data->{"price"}[0] =~ /^([0-9.]+) ([A-Z]+)$/
| |||||||||||||||||||||||||||||
| 102 | 0 | $info{$stock, "last"} = $1; | |||||||||||||||||||||||||||
| 103 | 0 | $info{$stock, "currency"} = $2; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | die "Unexpected date format" unless exists $data->{date} and $data->{date}->[0] =~ /([0-9]{2}[.][0-9]{2}[.][0-9]{4})$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $data->{"date"} and $data->{"date"}[0] =~ /([0-9]{2}[.][0-9]{2}[.][0-9]{4})$/
MC/DC0%0/2
exists $data->{"date"} and $data->{"date"}[0] =~ /([0-9]{2}[.][0-9]{2}[.][0-9]{4})$/
exists $data->{"date"}
$data->{"date"}[0] =~ /([0-9]{2}[.][0-9]{2}[.][0-9]{4})$/
Truth table0%0/3
A and B
A= exists $data->{"date"}B= $data->{"date"}[0] =~ /([0-9]{2}[.][0-9]{2}[.][0-9]{4})$/
| |||||||||||||||||||||||||||||
| 106 | 0 | $quoter->store_date(\%info, $stock, {eurodate => $1}); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | $info{$stock,"method"} = "finanzpartner"; | |||||||||||||||||||||||||||
| 109 | 0 | $info{$stock,"symbol"} = $stock; | |||||||||||||||||||||||||||
| 110 | 0 | $info{$stock,"success"} = 1; | |||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | $info{$stock,"errormsg"} = $@; | |||||||||||||||||||||||||||
| 115 | 0 | $info{$stock,"success"} = 0; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return wantarray ? %info : \%info; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 5 | 1; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 NAME | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | Finance::Quote::Finanzpartner - Obtain quotes from Finanzpartner.de. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | use Finance::Quote; | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | $q = Finance::Quote->new("Finanzpartner"); | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | %info = $q->fetch("finanzpartner","LU0055732977"); | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | This module obtains quotes from Finanzpartner.de (http://www.finanzpartner.de) by WKN or ISIN. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head1 LABELS RETURNED | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | The following labels may be returned by Finance::Quote::Finanzpartner: | ||||||||||||||||||||||||||||
| 143 | name, date, price, last, method. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Finanzpartner, http://www.finanzpartner.de/ | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Finance::Quote; | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||