App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Suffix/LJ.pm  view on Meta::CPAN

# Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2016 Kevin Ryde

# This file is part of Chart.
#
# Chart 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 3, or (at your option) any later
# version.
#
# Chart 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 Chart.  If not, see <http://www.gnu.org/licenses/>.


package App::Chart::Suffix::LJ;
use 5.010;
use strict;
use warnings;
use Locale::TextDomain 'App-Chart';

use App::Chart::Glib::Ex::MoreUtils;
use App::Chart;
use App::Chart::DownloadHandler::IndivChunks;
use App::Chart::LatestHandler;
use App::Chart::Sympred;
use App::Chart::TZ;
use App::Chart::Weblink;


my $timezone_ljubljana = App::Chart::TZ->new
  (name     => __('Ljubljana'),
   choose   => [ 'Europe/Ljubljana' ],
   fallback => 'CET-1');

my $pred = App::Chart::Sympred::Suffix->new ('.LJ');
$timezone_ljubljana->setup_for_symbol ($pred);


# (source-help! ljubljana-symbol?
# 	      __p('manual-node','Ljubljana Stock Exchange'))


#-----------------------------------------------------------------------------
# weblink - company info
#
# eg.
# Slovenian: http://www.ljse.si/cgi-bin/jve.cgi?SecurityID=DRKR&doc=818
# English:   http://www.ljse.si/cgi-bin/jve.cgi?SecurityID=DRKR&doc=3131
#

App::Chart::Weblink->new
  (pred => $pred,
   name => __('LJSE _Company Information'),
   desc => __('Open web browser at the Ljubljana Stock Exchange information page for this company'),
   proc => sub {
     my ($symbol) = @_;
     $symbol = URI::Escape::uri_escape(App::Chart::symbol_sans_suffix($symbol));
     my $lang = App::Chart::Glib::Ex::MoreUtils::lang_select (en => '3131',
                                                  sl => '818');
     return "http://www.ljse.si/cgi-bin/jve.cgi?SecurityID=$symbol&doc=$lang";
   });


#-----------------------------------------------------------------------------
# latest
#
# This uses the text file at
#
#     http://www.ljse.si/cgi-bin/jve.cgi?doc=2111
#
# which is
#
use constant BTS_URL => 'http://www.ljse.si/datoteke/BTStecajEUR.txt';
#
# The charset isn't specified in the http headers nor the file format specs
# but it's codepage 1250.  The server provides ETag and Last-Modified.
#
# The symbols in each file are cached, so it's usually possible to go
# straight to the right one.  If some symbols aren't where expected then
# both are downloaded to recheck.
#

App::Chart::LatestHandler->new
  (pred => $pred,
   available_tdate => \&available_tdate,
   proc => \&latest_download);

# per specs pdf file, available around 16:30 each day
sub available_tdate {
  App::Chart::Download::tdate_today_after (16,30, $timezone_ljubljana);
}

sub latest_download {
  my ($symbol_list) = @_;

  App::Chart::Download::status (__('LJSE price file'));
  my $resp = App::Chart::Download->get (BTS_URL,
                                       url_tags_key => 'LJ-BTStecajEUR');
  if (! $resp->is_success) {
    return; # 304 not modified
  }
  App::Chart::Download::write_latest_group (bts_parse ($resp));
}

my ($L0010, $L0020);

sub bts_parse {
  my ($resp) = @_;

  my @data = ();
  my $h = { source       => __PACKAGE__,
            url_tags_key => 'LJ-BTStecajEUR',
            resp         => $resp,
            currency     => 'EUR',
            date_format  => 'dmy',
            suffix       => '.TSP',
            data         => \@data };



( run in 0.707 second using v1.01-cache-2.11-cpan-39bf76dae61 )