X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FQuote.pl;h=33354cd6ab8e244cf2b68dbeef0ec429b047bfaf;hb=80577669c1c6f0f8f9cda0292b0dd21a98e86de7;hp=e72fd919e33c471c86aa10696c7ef2c5a3699ec5;hpb=bb482ed34735d13cad2a02cf0f5cdc322b6b9f89;p=infobot.git diff --git a/src/Modules/Quote.pl b/src/Modules/Quote.pl index e72fd91..33354cd 100644 --- a/src/Modules/Quote.pl +++ b/src/Modules/Quote.pl @@ -4,38 +4,58 @@ # Version: v0.1 # Author: Michael Urman # Licensing: Artistic +# changes from Morten Brix Pedersen (mbrix) and Tim Riker # package Quote; use strict; +sub commify { + my $input = shift; + $input = reverse $input; + $input =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; + return scalar reverse $input; +} + sub Quote { my $stock = shift; - my @results = &main::getURL("http://quote.yahoo.com/q?s=$stock&d=v1"); + my @results = + &::getURL( 'http://quote.yahoo.com/d/quotes.csv' + . "?s=$stock&f=sl1d1t1c1ohgv&e=.csv" ); - if (!scalar @results) { - &main::msg($main::who, "i could not get a stock quote :("); + if ( !scalar @results ) { + &::msg( $::who, "i could not get a stock quote :(" ); } - my $flathtml = join(" ", @results); + my ($reply); + foreach my $result (@results) { + + # get rid of the quotes + $result =~ s/\"//g; - local ($/) = "\n\n"; - for ($flathtml) { - s/.*?\//; - s/Chart.*//; - s/<.*?>//g; # remove HTML stuff. - s/\s{2,}/ /g; # reduce excessive spaces. - s/^\s+//; # get rid of leading whitespace - s/\s+$//; # get rid of trailing whitespace + my ( + $ticker, $recent, $date, $time, $change, + $open, $high, $low, $volume + ) = split( ',', $result ); + + # add some commas + # "+ 0" removes trailing cr/lf/etc. + my $newvol = commify( $volume + 0 ); + + $reply .= ' ;; ' if $reply; + $reply .= + "$ticker: $recent ($high/$low), $date $time, " + . "Opened $open, Volume $newvol, Change $change"; } - my $reply = $flathtml; - if ($reply eq "" or length($reply) > 160) { - $reply = "i couldn't get the quote for $stock. sorry. :("; + if ( $reply eq '' ) { + $reply = "i couldn't get the quote for $stock. sorry. :("; } - &main::performStrictReply($reply); + &::performStrictReply($reply); } 1; + +# vim:ts=4:sw=4:expandtab:tw=80