1 # -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*-
2 ################################
4 ################################
6 package BotModules::Stocks;
11 # XXX Per-channel configurable notification of stock changes
18 '' => 'This module gets stock quotes. Ask me a ticker symbol, I will retrieve the quote.',
19 'stock' => 'Call this command with a ticker symbol to get the current stock price and change. Syntax: stock FBAR',
25 my ($event, $message) = @_;
26 if ($message =~ /^\s*stocks?\s+(.+?)\s*$/osi) {
27 $self->getURI($event, "http://download.finance.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s=$1", $1);
29 return $self->SUPER::Told(@_);
31 return 0; # we've dealt with it, no need to do anything else.
36 my ($event, $uri, $output, $stock) = @_;
37 $self->debug($output);
38 my $message = "$event->{'from'}: ";
39 # The data currently listed in this format are: ticker symbol, last price, date, time, change, open price, daily high, daily low, and volume.
40 # -- http://help.yahoo.com/help/us/fin/quote/quote-05.html
41 my @stockValues = split(',', $output);
42 foreach my $part (@stockValues) {
43 $part =~ s/"//gos; # remove all quotes. Bit of a hack, but... XXX
45 if ($stockValues[4] > 0) {
46 $stockValues[4] = 'up ' . (0+$stockValues[4]);
47 } elsif ($stockValues[4] < 0) {
48 $stockValues[4] = 'down ' . (0-$stockValues[4]);
50 $stockValues[4] = 'no change';
52 $message .= "Stock quote for $stockValues[0]: $stockValues[1], $stockValues[4] (low: $stockValues[7], high: $stockValues[6])";
53 $self->say($event, $message);