Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use v5.12;
- use Cwd qw(abs_path);
- use FindBin;
- use lib abs_path(qq{$FindBin::Bin});
- use Time::HiRes qw( gettimeofday tv_interval );
- my $t0 = [ gettimeofday ];
- # Start logging
- use Log::Log4perl qw(:easy);
- binmode( STDOUT, ":utf8" );
- use Log::Log4perl::CommandLine ( ':all', ':logconfig', abs_path(qq{$FindBin::Bin/logging.cfg}) );
- INFO("Begin Program");
- DEBUG(qq{Logging configuration from $FindBin::Bin/logging.cfg});
- DEBUG("Debug flag turned on");
- TRACE("Trace flag turned on");
- #
- # Do Stuff
- #
- use Mojo::UserAgent;
- my $quoteurl = q{https://in.finance.yahoo.com/quote/^DJI}; # <div id="quote-header-info"
- # Fresh user agent
- my $ua = Mojo::UserAgent->new;
- my $res = $ua->get($quoteurl)->result;
- my $target = q{div#quote-header-info.quote-header-section.Cf.Pos(r).Mb(5px).Maw($maxModuleWidth).Miw($minGridWidth).smartphone_Miw(ini).Miw(ini)!--tab768.Miw(ini)!--tab1024.Mstart(a).Mend(a).Px(20px).smartphone_Pb(0px).smartphone_Mb(0px)};
- my @text;
- foreach my $item ( $res->dom->find($target)->each) {
- TRACE(q{item - TOP of item loop: } . $item);
- for my $n ($item->descendant_nodes->each) {
- TRACE(q{descendant - TOP of descendant loop});
- if ($n->type eq 'text') {
- DEBUG(q{text: } . $n->content);
- push @text, $n->content;
- }
- TRACE(q{descendant - BOTTOM of descendant loop});
- } # for my $n
- TRACE(q{item - BOTTOM of item loop: });
- } # foreach my $item
- my $idx = 0;
- foreach my $line (@text) {
- DEBUG(qq{$idx $line});
- $idx++;
- }
- #
- # Output
- #
- my ($label, undef, $trump_current, $ts) = @text;
- $trump_current =~ s/,//;
- my $obama_end = 19813.55;
- my $diff = $trump_current - $obama_end;
- my $outline = sprintf(qq{%s}, $label);
- say qq{\n\t} . $outline;
- INFO $outline;
- $outline = sprintf(qq{%5s %6.2f (%s)}, q{Trump}, $trump_current, $text[4]);
- say qq{\n\t} . $outline;
- INFO $outline;
- $outline = sprintf(qq{%5s %6.2f (%s)}, q{Obama}, $obama_end, q{last day in office});
- say qq{\t} . $outline;
- INFO $outline;
- $outline = sprintf(qq{%5s %s-%s}, q{-----}, q{--------}, q{-----------------------});
- say qq{\t} . $outline;
- INFO $outline;
- $outline = sprintf(qq{%5s % 6.2f}, q{Diff}, ( $diff ));
- say qq{\t} . $outline;
- INFO $outline;
- say qq{\n};
- # Exit
- INFO sprintf (q{End Program - ET: %02.2f seconds}, tv_interval($t0));
- exit;
- __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement