Skip Menu |

This queue is for tickets about the Finance-Quote CPAN distribution.

Report information
The Basics
Id: 39981
Status: resolved
Worked: 15 min
Priority: 0/
Queue: Finance-Quote

People
Owner: eco [...] ecocode.net
Requestors: JANW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Module for finanzpartner.de
Here is a module to fetch quotes from finanzpertner.de. Maybe you can include it in the next release.
Subject: Finanzpartner.pm
# Finance::Quote Perl module to retrieve quotes from Finanzpartner.de # Copyright (C) 2007 Jan Willamowius <jan@willamowius.de> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA package Finance::Quote::Finanzpartner; use strict; use HTML::TableExtract; use vars qw($VERSION); $VERSION = '0.1'; my $FINANZPARTNER_URL = "http://www.finanzpartner.de/fi/"; sub methods {return (finanzpartner => \&finanzpartner);} sub labels { return (finanzpartner=>[qw/name date price last method/]); } # TODO # Trim leading and tailing whitespaces (also non-breakable whitespaces) sub trim { $_ = shift(); s/^\s*//; s/\s*$//; s/&nbsp;//g; return $_; } # Convert number separators to US values sub convert_price { $_ = shift; s/\./@/g; s/,/\./g; s/@/,/g; return $_; } sub finanzpartner { my $quoter = shift; # The Finance::Quote object. my @stocks = @_; my $ua = $quoter->user_agent(); my %info; foreach my $stock (@stocks) { $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)'); my $response = $ua->get($FINANZPARTNER_URL . $stock . '/'); $info{$stock,"success"} = 0; if (!$response -> is_success()) { $info{$stock,"errormsg"} = "HTTP failure"; } else { my $te = new HTML::TableExtract(depth => 0, count => 2); $te->parse($response->content); my $table = $te->first_table_found; if (trim($table->cell(1,0)) ne 'Fondsname:') { $info{$stock,"errormsg"} = "Couldn't parse website"; } else { $info{$stock,"name"} = $table->cell(1,1); my $quote = $table->cell(7,1); my @part = split(/\s/, $quote); $info{$stock,"currency"} = $part[1]; $part[2] =~ s/\(//g; $part[2] =~ s/\)//g; $quoter->store_date(\%info, $stock, {eurodate => $part[2]}); $info{$stock,"price"} = convert_price(trim($part[0])); $info{$stock,"last"} = $info{$stock,"price"}; $info{$stock,"success"} = 1; $info{$stock,"method"} = "finanzpartner"; $info{$stock,"symbol"} = $stock; } } } return wantarray ? %info : \%info; } 1; =head1 NAME Finance::Quote::Finanzpartner - Obtain quotes from Finanzpartner.de. =head1 SYNOPSIS use Finance::Quote; $q = Finance::Quote->new("Finanzpartner"); %info = $q->fetch("finanzpartner","LU0055732977"); =head1 DESCRIPTION This module obtains quotes from Finanzpartner.de (http://www.finanzpartner.de) by WKN or ISIN. =head1 LABELS RETURNED The following labels may be returned by Finance::Quote::Finanzpartner: name, date, price, last, method. =head1 SEE ALSO Finanzpartner, http://www.finanzpartner.de/ Finance::Quote; =cut
Hi Jan Would you mind adding a test file ? Thank you for your contribution ! -- Erik
Here is a test file.
#!/usr/bin/perl -w use strict; use Test; BEGIN {plan tests => 8}; use Finance::Quote; # Test finanzpartner functions. my $year = (localtime())[5] + 1900; my $lastyear = $year - 1; my $q = Finance::Quote->new("Finanzpartner"); my %quotes = $q->finanzpartner("LU0055732977","BOGUS"); ok(%quotes); # Check that the last and date values are defined. ok($quotes{"LU0055732977","success"}); ok($quotes{"LU0055732977","last"} > 0); ok(length($quotes{"LU0055732977","date"}) > 0); ok(substr($quotes{"LU0055732977","isodate"},0,4) == $year || substr($quotes{"LU0055732977","isodate"},0,4) == $lastyear); ok(substr($quotes{"LU0055732977","date"},6,4) == $year || substr($quotes{"LU0055732977","date"},6,4) == $lastyear); ok($quotes{"LU0055732977","currency"} eq "USD"); # Check that a bogus fund returns non-success. ok($quotes{"BOGUS","success"} == 0);
On Sun Oct 12 17:38:27 2008, JANW wrote: Show quoted text
> Here is a test file.
The module has been added to the repo for the next release. Thank you for your work! -- Erik