]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Quote.pl
Initial revision
[infobot.git] / src / Modules / Quote.pl
1 #
2 #  Quote.pl: retrieve stock quotes from yahoo
3 #            heavily based on Slashdot.pl
4 #   Version: v0.1
5 #    Author: Michael Urman <mu@zen.dhis.org>
6 # Licensing: Artistic
7 #
8
9 package Quote;
10
11 use strict;
12
13 sub Quote {
14     my $stock = shift;
15     my @results = &main::getURL("http://quote.yahoo.com/q?s=$stock&d=v1");
16
17     if (!scalar @results) {
18         &main::msg($main::who, "i could not get a stock quote :(");
19     }
20
21     my $flathtml = join(" ", @results);
22
23     local ($/) = "\n\n";
24     for ($flathtml) {
25         s/.*?\<tr align=right\>//;
26         s/Chart.*//;
27         s/<.*?>//g;             # remove HTML stuff.
28         s/\s{2,}/ /g;           # reduce excessive spaces.
29         s/^\s+//;               # get rid of leading whitespace
30         s/\s+$//;               # get rid of trailing whitespace
31     }
32     my $reply = $flathtml;
33
34     if ($reply eq "" or length($reply) > 160) {
35         $reply = "i couldn't get the quote for $stock. sorry. :(";
36     }
37
38     &main::performStrictReply($reply);
39 }
40
41 1;