Quote/Deka.pm

filter: Statementstmt 38.3% 23 / 60 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 6 totaltotal 32.5% 29 / 89 CC 12 SCAR 45.4
CC
12
Cov
31%
deka
156.0
convert_price
2.0
dekaurl
2.0
CRAP 94.1
« Quote/SIX.pm ↑ Summary Quote/SwissFundData.pm »
1 #!/usr/bin/perl -w
2 #
3 # Deka import modul based on Union.pm
4 # Version 2016-01-12
5 # vi: set ts=2 sw=2 noai expandtab ic showmode showmatch:
6  
7 package Finance::Quote::Deka;
8  
9 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 our $VERSION = '1.72'; # VERSION
14  
15 5 our $DISPLAY = 'Deka Investments, DE';
16 5 our @LABELS = qw/exchange name date isodate price method/;
17 5 our $METHODHASH = {subroutine => \&deka,
18 display => $DISPLAY,
19 labels => \@LABELS};
20  
21 5 my $AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36';
22  
23 10 ▶sub methodinfo {
Subroutine methodinfo: called CC=1 SCAR=0.0
Pod undocumented
24 return (
25 10 deka => $METHODHASH,
26 germany => $METHODHASH,
27 );
28 }
29  
30 5 ▶sub labels {
Subroutine labels: called CC=1 SCAR=0.0
Pod undocumented
31 5 my %m = methodinfo();
32 5 return map {$_ => [@{$m{$_}{labels}}] } keys %m;
33 }
34  
35 5 ▶sub methods {
Subroutine methods: called CC=1 SCAR=0.0
Pod undocumented
36 5 my %m = methodinfo();
37 5 return map {$_ => $m{$_}{subroutine} } keys %m;
38 }
39  
40 # =======================================================================
41 # The deka routine gets quotes of DEKA funds (Deka Investments)
42 # On their website DEKA provides a csv file in the format
43 # label1;label2;...
44 # symbol1;name1;date1;date_before1;bid1;...
45 # symbol2;name2;date2;date_before2,bid2,...
46 # ...
47 #
48 # This subroutine was written by Andre Joost <andrejoost@gmx.de>
49  
50 # Convert number separators to US values
51 0 ▶sub convert_price {
Subroutine convert_price: not called CC=1 SCAR=6.9
Pod undocumented
52 0 $_ = shift;
53 0 tr/.,/,./ ;
54 0 return $_;
55 }
56  
57 sub deka
58 0 ▶{
Subroutine deka: not called CC=12 SCAR=50.5
Pod undocumented
59 0 my $quoter = shift;
60 0 my @funds = @_;
61 0 ▶ return unless @funds;
Branch: 1 branch
BranchTrueFalseTotal
unless @funds 0 0 0
62 0 my $ua = $quoter->user_agent;
63 0 $ua->agent($AGENT);
64 0 my (%fundhash, @q, %info, $tempdate);
65  
66 # create hash of all funds requested
67 0 foreach my $fund (@funds)
68 {
69 0 $fundhash{$fund} = 0;
70 }
71  
72 # get csv data
73 0 my $response = $ua->request(GET &dekaurl);
74  
75  
76 0 ▶ if ($response->is_success)
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
77 {
78  
79 # process csv data
80 0 foreach (split('\015?\012',$response->content))
81 {
82 # @q = $quoter->parse_csv($_) or next;
83 0 ▶ @q = split(/;/) or next;
Branch: 1 branch
BranchTrueFalseTotal
@q = split(/;/, $_, 0) or next 0 0 0
84 0 ▶ next unless (defined $q[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $q[0] 0 0 0
85 0 ▶ if (exists $fundhash{$q[0]})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fundhash{$q[0]}) 0 0 0
86 {
87 0 $fundhash{$q[0]} = 1;
88  
89  
90 0 $info{$q[0], "exchange"} = "DEKA";
91 0 $info{$q[0], "name"} = $q[1];
92 0 $info{$q[0], "symbol"} = $q[0];
93 0 $tempdate = $q[2];
94 0 $quoter->store_date(\%info, $q[0], {eurodate => $tempdate});
95 0 $info{$q[0], "price"} = convert_price($q[4]);
96 0 $info{$q[0], "last"} = convert_price($q[4]);
97  
98 0 $info{$q[0], "method"} = "deka";
99 0 $info{$q[0], "currency"} = $q[8];
100 0 $info{$q[0], "success"} = 1;
101 }
102 }
103  
104 # check to make sure a value was returned for every fund requested
105 0 foreach my $fund (keys %fundhash)
106 {
107 0 ▶ if ($fundhash{$fund} == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($fundhash{$fund} == 0) 0 0 0
108 {
109 0 $info{$fund, "success"} = 0;
110 0 $info{$fund, "errormsg"} = "No data returned";
111 }
112 }
113 }
114 else
115 {
116 0 foreach my $fund (@funds)
117 {
118 0 $info{$fund, "success"} = 0;
119 0 $info{$fund, "errormsg"} = "HTTP error";
120 }
121 }
122  
123 0 ▶ return wantarray() ? %info : \%info;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
124 }
125  
126 # DEKA provides a csv file named fondspreise.csv containing the prices of all
127 # their funds for the most recent business day.
128  
129 sub dekaurl
130 0 ▶{
Subroutine dekaurl: not called CC=1 SCAR=6.9
Pod undocumented
131 0 return "https://www.deka.de/privatkunden/pflichtseiten/fondspreise?service=fondspreislisteExportController&action=exportCsv&typ=inVertrieb";
132 }
133  
134 5 1;
135  
136 =head1 NAME
137  
138 Finance::Quote::Deka - Obtain quotes from DEKA (Wertpapierhaus der Sparkassen).
139  
140 =head1 SYNOPSIS
141  
142 use Finance::Quote;
143  
144 $q = Finance::Quote->new;
145  
146 %stockinfo = $q->fetch("deka","DE0008474503");
147  
148 =head1 DESCRIPTION
149  
150 This module obtains information about DEKA managed funds.
151  
152 Information returned by this module is governed by DEKA's terms
153 and conditions.
154  
155 =head1 LABELS RETURNED
156  
157 The following labels may be returned by Finance::Quote::DEKA:
158 exchange, name, date, price, last.
159  
160 =head1 SEE ALSO
161  
162 DEKA (Deka Investments), http://www.deka.de/
163  
164 =cut
« Quote/SIX.pm ↑ Summary Quote/SwissFundData.pm »