Menu

LeRevenu.pm

2009-10-09
2013-06-03
  • Hubert de Fraysseix

    It seems that since a week or so that script does not work anymore: " can't call method rows on an undefined value…".
    Something must have changed on LeRevenu website.
    Would it be possible to correct that problem.
    Thanks,
    Hubert

     
  • bab Fra

    bab Fra - 2009-10-13

    I have the same problem with LeRevenu website; I think the website has been updated… and so the perl script LeRevenu.pm in /usr/lib/perl5/vendor_perl/5.10.0/Finance/Quote has to be modified… If anyone has perl knowledge?

     
  • Wander Luiz Oliveira de Castro

    Hi, I made some modifications on LeRevenu.pm
    I hope this would help.

        #!/usr/bin/perl -w
        #
        #    Copyright (C) 1998, Dj Padzensky <djpadz@padz.net>
        #    Copyright (C) 1998, 1999 Linas Vepstas <linas@linas.org>
        #    Copyright (C) 2000, Yannick LE NY <y-le-ny@ifrance.com>
        #    Copyright (C) 2000, Paul Fenwick <pjf@cpan.org>
        #    Copyright (C) 2000, Brent Neal <brentn@users.sourceforge.net>
        #    Copyright (C) 2001, Rob Sessink <rob_ses@users.sourceforge.net>
        #    Copyright (C) 2005, Morten Cools <morten@cools.no>
        #    Copyright (C) 2006, Dominique Corbex <domcox@sourceforge.net>
        #
        #    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., 59 Temple Place - Suite 330, Boston, MA
        #    02111-1307, USA
        #
        #
        # This code derived from Padzensky's work on package Finance::YahooQuote,
        # but extends its capabilites to encompas a greater number of data sources.
        #
        # Version 1.18 by Wander Luiz Castro <wanderluiz.castro at bol dot com dot br>
        #             
        #
       
        require 5.005;
       
        use strict;
       
        package Finance::Quote::LeRevenu;
       
        use vars qw($VERSION $LR_URL);
       
        use LWP::UserAgent;
        use HTTP::Request::Common;
        use HTML::TableExtract;
       
        $VERSION = '1.18';
       
        my $LR_URL = 'http://bourse.lerevenu.com/v2/recherchenom.hts';
       
       
        sub methods { return ( france => \&lerevenu,
        lerevenu => \&lerevenu); }
        {
        my @labels = qw/name last date isodate p_change open high low close volume currency method exchange/;
       
        sub labels { return (france => \@labels,
             lerevenu => \@labels); }
        }
       
        sub lerevenu {
       
        my $quoter = shift;
        my @stocks = @_;
        my (%info,$reply,$url,$te,$ts,$row,$style);
        my $ua = $quoter->user_agent();
       
        foreach my $stocks (@stocks)
        {
        $url="$LR_URL?recherchenom=$stocks&p=20";
        $reply = $ua->request(GET $url); 
       
        if ($reply->is_success)
        {
        # print STDERR $reply->content,"\n";
       
        $te= new HTML::TableExtract(keep_html=>1);
        $te->parse($reply->content);
        # debug
        # foreach $ts ($te->tables) {
        # print "Table (", join(',', $ts->coords), "):\n";
        # foreach $row ($ts->rows) {
        # print join(',', @$row), "\n";
        #     }
        #    }
       
        unless ($te->table(5, 1))
        {
        $info {$stocks,"success"} = 0;
        $info {$stocks,"errormsg"} = "name $stocks not found";
        next;
        }
        my @rows;
        my $name;
        my $isin;
        my $exchange=$te->table(5, 1)->cell(1,2);
        $style=$te->table(5, 1)->cell(1,0);
        if (($style =~ m/href=".*?getFiche.php\?id=(.*?)\%2C(.*?)".*?>(.*?)</)) {
        $style = "action";
        $url = "http://bourse.lerevenu.com/v2/action.hts?id=$1%2C$2";
        $isin = $1;
        $name = $3;
        }
        else {
        if ($style =~ m/href="(.*?).hts\?id=(.*?)\%2C(.*?)">(.*?)</) {
        $style = $1;
        $url = "http://bourse.lerevenu.com/v2/$1.hts?id=$2%2C$3";
        $isin = $2;
        $name = $4;
       
        }
        }
       
        $reply = $ua->request(GET $url); 
        if ($reply->is_success)
        {
        $te= new HTML::TableExtract(gridmap=>1);
        $te->parse($reply->content);
        SWITCH: for ($style){
        # style=stock
        /action/ && do {
        $info{$stocks, "name"}=$name;
        $info{$stocks, "success"}=1;
        $info{$stocks, "exchange"}=$exchange;
        $info{$stocks, "method"}="lerevenu";
        $info{$stocks,"currency"}="EUR";
        # Dernier
        ($info{$stocks, "last"}=$te->table(6, 1)->cell(2,1)) =~ s/*//g;
        ($info{$stocks, "close"}=$te->table(6, 1)->cell(2,1)) =~ s/*//g;
        # Date
        $quoter->store_date(\%info, $stocks, {eurodate => $te->table(6, 1)->cell(0,1)});
        # Var %
        ($info{$stocks, "p_change"}=$te->table(6, 1)->cell(3,1)) =~ s/*//g;
        # Premier
        ($info{$stocks, "open"}=$te->table(6, 1)->cell(4,1)) =~ s/*//g;
        # Haut
        ($info{$stocks, "high"}=$te->table(6, 1)->cell(5,1)) =~ s/*//g;
        # Bas
        ($info{$stocks, "low"}=$te->table(6, 1)->cell(6,1)) =~ s/*//g;
        # Volume
        ($info{$stocks, "volume"}=$te->table(6, 1)->cell(7,1)) =~ s/*//g;
        #Isin
        $info{$stocks, "symbol"}=$isin;
        last SWITCH;
        };
       
        # style=bond
        /obligation/ && do {
        $info{$stocks, "name"}=$name;
        $info{$stocks, "success"}=1;
        $info{$stocks, "exchange"}=$exchange;
        $info{$stocks, "method"}="lerevenu";
        $info{$stocks,"currency"}="EUR";
        # Dernier
        #print $te->table(3, 0)->cell(2,3);
        ($info{$stocks, "last"}=$te->table(2, 0)->cell(0,1)) =~ s/*//g;
        ($info{$stocks, "close"}=$te->table(2, 0)->cell(0,1)) =~ s/*//g;
        # Date
        $quoter->store_date(\%info, $stocks, {eurodate => $te->table(3, 0)->cell(0,1)});
        # Var %
        ($info{$stocks, "p_change"}=$te->table(3, 0)->cell(3,1)) =~ s/*//g;
        # Premier
        ($info{$stocks, "open"}=$te->table(3, 0)->cell(4,1)) =~ s/*//g;
        # Haut
        ($info{$stocks, "high"}=$te->table(3, 0)->cell(5,1)) =~ s/*//g;
        # Bas
        ($info{$stocks, "low"}=$te->table(3, 0)->cell(6,1)) =~ s/*//g;
        # Volume
        ($info{$stocks, "volume"}=$te->table(3, 0)->cell(7,1)) =~ s/*//g;
        #Isin
        $info{$stocks, "symbol"}=$isin;
        last SWITCH;
        };
       
        # style= warrant
        /warrant/ && do {
        $info{$stocks, "name"}=$name;
        $info{$stocks, "success"}=1;
        $info{$stocks, "exchange"}=$exchange;
        $info{$stocks, "method"}="lerevenu";
        $info{$stocks,"currency"}="EUR";
        # Dernier
        ($info{$stocks, "last"}=$te->table(3, 0)->cell(2,1)) =~ s/*//g;
        ($info{$stocks, "close"}=$te->table(3, 0)->cell(2,1)) =~ s/*//g;
        # Date
        $quoter->store_date(\%info, $stocks, {eurodate => $te->table(3, 0)->cell(0,1)});
        # Var %
        ($info{$stocks, "p_change"}=$te->table(3, 0)->cell(3,1)) =~ s/*//g;
        # Premier
        ($info{$stocks, "open"}=$te->table(3, 0)->cell(4,1)) =~ s/*//g;
        # Haut
        ($info{$stocks, "high"}=$te->table(3, 0)->cell(5,1)) =~ s/*//g;
        # Bas
        ($info{$stocks, "low"}=$te->table(3, 0)->cell(6,1)) =~ s/*//g;
        # Volume
        ($info{$stocks, "volume"}=$te->table(3, 0)->cell(7,1)) =~ s/*//g;
        #Isin
        $info{$stocks, "symbol"}=$isin;
        last SWITCH;
        };
       
        # style=fund
        /opcvm/ && do {
       
        $info{$stocks, "name"}=$name;
        $info{$stocks, "success"}=1;
        $info{$stocks, "exchange"}=$exchange;
        $info{$stocks, "method"}="lerevenu";
        my $currency = $te->table(3, 0)->cell(0,1);
        $currency =~ s/*//g;
        $info{$stocks,"currency"}=$currency;
        # Dernier
        ($info{$stocks, "last"}=$te->table(3, 0)->cell(0,1)) =~ s/*//g;
        # Date
        $quoter->store_date(\%info, $stocks, {eurodate => $te->table(3, 0)->cell(2,3)});
        # Var %
        ($info{$stocks, "p_change"}=$te->table(3, 0)->cell(0,2)) =~ s/*//g;
        # Actif
        my $nav;
        $nav=$te->table(7, 7)->cell(0,1);
        $nav =~ s/*//g;
        $info{$stocks, "nav"}=($nav * 1000000);
        #Isin
        $info{$stocks, "symbol"}=$isin;
        last SWITCH;
        };
       
        # style=indice
        /indice/ && do { 
        $info{$stocks, "name"}=$name;
        $info{$stocks, "success"}=1;
        $info{$stocks, "exchange"}=$exchange;
        $info{$stocks, "method"}="lerevenu";
        $info{$stocks,"currency"}="EUR";
        # Dernier
        ($info{$stocks, "last"}=$te->table(5, 1)->cell(2,1)) =~ s/*//g;
        ($info{$stocks, "close"}=$te->table(5, 1)->cell(2,1)) =~ s/*//g;
        # Date
        $quoter->store_date(\%info, $stocks, {eurodate => $te->table(5, 1)->cell(0,1)});
        # Var %
        ($info{$stocks, "p_change"}=$te->table(5, 1)->cell(3,1)) =~ s/*//g;
        # Premier
        ($info{$stocks, "open"}=$te->table(5, 1)->cell(4,1)) =~ s/*//g;
        # Haut
        ($info{$stocks, "high"}=$te->table(5, 1)->cell(5,1)) =~ s/*//g;
        # Bas
        ($info{$stocks, "low"}=$te->table(5, 1)->cell(6,1)) =~ s/*//g;
        #Isin
        $info{$stocks, "symbol"}=$isin;
        last SWITCH;
        };
       
        { #error
        $info {$stocks,"success"} = 0;
        $info {$stocks,"errormsg"} = "Parse error";
        }
       
        }
            }
       
       
       
        }
        else {
             $info{$stocks, "success"}=0;
        $info{$stocks, "errormsg"}="Error retreiving $stocks ";
           }
         }
         return wantarray() ? %info : \%info;
         return \%info;
        }
        1;
       
        =head1 NAME
       
        Finance::Quote::LeRevenu Obtain quotes from http://bourse.lerevenu.com.
       
        =head1 SYNOPSIS
       
            use Finance::Quote;
       
            $q = Finance::Quote->new;
       
            %info = Finance::Quote->fetch("LeRevenu","FR0000031122");  # Only query LeRevenu
            %info = Finance::Quote->fetch("france","ml"); # Failover to other sources OK.
       
        =head1 DESCRIPTION
       
        This module fetches information from the "Paris Stock Exchange",
        http://bourse.lerevenu.com. All stocks are available.
       
        This module is loaded by default on a Finance::Quote object. It's
        also possible to load it explicity by placing "LeRevenu" in the argument
        list to Finance::Quote->new().
       
        This module provides both the "lerevenu" and "france" fetch methods.
        Please use the "france" fetch method if you wish to have failover
        with future sources for French stocks. Using the "lerevenur" method
        will guarantee that your information only comes from the Paris Stock Exchange.
        
        Information obtained by this module may be covered by http://bourse.lerevenu.com
        terms and conditions See http://bourse.lerevenu.com for details.
       
        =head1 LABELS RETURNED
       
        The following labels may be returned by Finance::Quote::LeRevenu :
        name, last, date, p_change, open, high, low, close,
        volume, currency, method, exchange.
       
        =head1 SEE ALSO
       
        Le Revenu, http://bourse.lerevenu.com
       
        =cut

     

Log in to post a comment.