Skip to content

Instantly share code, notes, and snippets.

@poppen
Created August 20, 2011 11:32
Show Gist options
  • Select an option

  • Save poppen/1158987 to your computer and use it in GitHub Desktop.

Select an option

Save poppen/1158987 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode;
use Finance::Quote;
use URI;
use Web::Scraper;
my $q = Finance::Quote->new;
my %index_quotes = $q->fetch( "bloomberg_stocks_index", 'MXKO:IND' );
my %etf_quotes = $q->fetch( "bloomberg_etf", '1680:JP' );
my $usdjpy_p_change = _get_usdjpy_p_change();
my $mxko1680 = sprintf "%s",
$etf_quotes{ '1680:JP', 'nav' }
* ( 1 + ( $index_quotes{ 'MXKO:IND', 'p_change' } / 100 ) )
* ( 1 + $usdjpy_p_change / 100 );
print encode( 'utf8', "名前:" ), $etf_quotes{ '1680:JP', 'name' }, "\n";
print encode( 'utf8', "推定nav:" ), $mxko1680, encode( 'utf8', "円" ),
"\n";
# Fetching usd-jpy percent change
sub _get_usdjpy_p_change {
my $uri = URI->new("http://www.bloomberg.com/markets/");
my $scraper = scraper {
process
'//td[@class="name" and text()="USD-JPY"]/following-sibling::node()[3]',
p_change => [ 'TEXT', sub {s/%$//} ];
};
my $result = $scraper->scrape($uri);
return $result->{p_change};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment